[Tutor] Tkinter - How to get multilple windows
Alan Gauld
alan.gauld at blueyonder.co.uk
Sun Jan 4 14:15:53 EST 2004
> >Instantiate a new window object which inherits from
> >TopLevel rather than a simple Frame.
def openNew(self):
app1 = App1(self)
app1.mainloop()
You don;t need the mainloop here, there is already a
mainloop running, it will send the events to your window
object OK
> #quit class
> class App1(Toplevel):
> def __init__(self,master=None):
> Toplevel.__init__(self,master)
> self.grid()
> self.createWidgets()
>
> def createWidgets(self):
> textButton =
Button(self,text="Quit",command=self.quit)
> textButton.grid()
> app = App() #instance of the Application
> app.master.title("Sample program")
> app.mainloop() #wait for the events
> 1. I am getting two windows
Which is what you wanted, yes? I assume the 2nd window only
comes up after pressing the button?
> 2. I want only the object of APP1 to quit not the entire program.
Only run the one mainloop. Otherwise it should be OK.
And you may not want to use self.quit - I think theres
a self.close() for TopLevel... Try a dir(TopLevel)...
Alan g
More information about the Tutor
mailing list