在变量中传递多行

时间:2011-04-01 23:00:33

标签: python variables

如何将NewsTabs.py中的变量“tabbing”传递给GUI.py并让它在GUI.py中运行

GUI.py

from Tkinter import *
from notebook import *
import NewsFeed
import NewsTabs

root = Tk()
n = notebook(root, TOP)

f1 = Frame(n())

NewsTabs.Tabs

f2 = Frame(n())
lable1 = Label(f2, text="Pre Alpha! \n Version 0.0.0.1 \n Fourms not yet implemented")
lable1.grid(row=1,column=1)

n.add_screen(f1, "News")
n.add_screen(f2, "Fourms")

frame = Frame(width=max, height=max, bg="white")
frame.pack()
root.title('RazeTheWorld')

root.mainloop()

NewsTabs.py

Tabbing = {
w = Button(f1, text="Main", bd=0, bg="white")
w.grid(row=0,column=1, sticky = W)
w1 = Button(f1, text="News", bd=0, bg="white")
w1.grid(row=1,column=1, sticky = W)
w2 = Button(f1, text="VideoReview", bd=0, bg="white")
w2.grid(row=2,column=1, sticky = W)
w3 = Button(f1, text="VideoNews", bd=0, bg="white")
w3.grid(row=3,column=1, sticky = W)
w4 = Button(f1, text="VideoGameplay", bd=0, bg="white")
w4.grid(row=4,column=1, sticky = W)
w5 = Button(f1, text="Hardware", bd=0, bg="white")
w5.grid(row=5,column=1, sticky = W)
w6 = Button(f1, text="CPU", bd=0, bg="white")
w6.grid(row=6,column=1, sticky = W)
w7 = Button(f1, text="Grapics", bd=0, bg="white")
w7.grid(row=7,column=1, sticky = W)
}

def Tabs():
    return Tabbing

1 个答案:

答案 0 :(得分:0)

在任何其他源文件中(在您的情况下,可能是GUI.py):

import NewsTabs

tabs = NewsTabs.Tabs()

或:

import NewsTabs
tabs = NewsTabs.tabbing

如果NewsTab 具有常量值,第一个将非常有用。

请注意,您的变量Tabbing不是有效的Python。你需要把花括号内的所有代码都放在外面;那么,你想要列出你创建的对象:

tabbing = [w, w1, w2, w3, w4, w5, w6, w7]