|
Post by Trey Brown on Jul 12, 2014 9:47:29 GMT -5
So far, we have learned how to make interactive buttons, labels, entries, and the main window. Today we will learn how to convey a new window. I will show you the code, then I will explain the new content.
from Tkinter import * import sys
class App: def newWin(self): self.win = Tk() self.win.title('New Window') #Add widgets below like so: self.txt = Label(win, text="New Window") self.txt.pack() self.win.mainloop() def __init__(self): self.root = Tk() self.root.title('Home Page') self.butt = Button(root, text='Click for newWin!', command=self.newWin) self.butt.pack() self.root.mainloop() if __name__ == "__main__": app = App() app()
What I have changed here, is we made our entire program consist of a class. I expect you to already have looked into these basic Python concepts so you should know how to work around classes. The only new thing in here is the new window. We simply made a button that went to a function that started a new root if you will. We then follow the same syntax for the widgets as normal but following that window.
|
|