Pass multiple lines in a variable
How would I pass variable "tabbing" from NewsTabs.py to GUI.py and have it run in 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
In any other source file (in your case, probably GUI.py):
import NewsTabs
tabs = NewsTabs.Tabs()
or:
import NewsTabs
tabs = NewsTabs.tabbing
The first would be useful if NewsTab does not have a constant value.
Be aware that your variable Tabbing
is not valid Python. You need to take all of the code inside the curly braces and put it outside; then, you want to make a list of the objects you created:
tabbing = [w, w1, w2, w3, w4, w5, w6, w7]
精彩评论