From: Chris Hare on 1 Aug 2010 18:15 I hope I can explain this correctly. I have a GUI, which is already being processed by a mainloop. I want to be able to open a second window so the user can interact with specific information in the second window. I pulled together this code example from Tkinter import * class Net: def __init__(self,tkWin): self.window = tkWin def show(self,t): self.l = Label(self.window,text=t) self.l.grid() button = Button(self.window, text="Again") button.bind("<Button-1>", self.Again) button.grid() def Again(self,event): win3 = Tk() x = Net(win3) x.show("window 3") root = Tk() root.title = "test" f = Frame(root,bg="Yellow") l = Label(f,text="window 1") f.grid() l.grid() win2 = Tk() x = Net(win2) x.show("window 2") if __name__ == "__main__": root.mainloop() Is this the right way to do things, or would you suggest something different? Thanks, Chris
From: rechardchen on 1 Aug 2010 21:33 于 2010-8-2 6:15, Chris Hare 写道: > I hope I can explain this correctly. > > I have a GUI, which is already being processed by a mainloop. I want to be able to open a second window so the user can interact with specific information in the second window. I pulled together this code example > > from Tkinter import * > > class Net: > def __init__(self,tkWin): > self.window = tkWin > def show(self,t): > self.l = Label(self.window,text=t) > self.l.grid() > button = Button(self.window, text="Again") > button.bind("<Button-1>", self.Again) > button.grid() > def Again(self,event): > win3 = Tk() > x = Net(win3) > x.show("window 3") > > root = Tk() > root.title = "test" > f = Frame(root,bg="Yellow") > l = Label(f,text="window 1") > f.grid() > l.grid() > > win2 = Tk() > x = Net(win2) > x.show("window 2") > if __name__ == "__main__": > root.mainloop() > > Is this the right way to do things, or would you suggest something different? > > Thanks, > Chris > Using Tkinter.Toplevel may be better. :)
From: Chris Hare on 2 Aug 2010 07:46 On Aug 1, 2010, at 8:33 PM, rechardchen wrote: > äº 2010-8-2 6:15, Chris Hare åé: >> I hope I can explain this correctly. >> >> I have a GUI, which is already being processed by a mainloop. I want to be able to open a second window so the user can interact with specific information in the second window. I pulled together this code example >> >> from Tkinter import * >> >> class Net: >> def __init__(self,tkWin): >> self.window = tkWin >> def show(self,t): >> self.l = Label(self.window,text=t) >> self.l.grid() >> button = Button(self.window, text="Again") >> button.bind("<Button-1>", self.Again) >> button.grid() >> def Again(self,event): >> win3 = Tk() >> x = Net(win3) >> x.show("window 3") >> >> root = Tk() >> root.title = "test" >> f = Frame(root,bg="Yellow") >> l = Label(f,text="window 1") >> f.grid() >> l.grid() >> >> win2 = Tk() >> x = Net(win2) >> x.show("window 2") >> if __name__ == "__main__": >> root.mainloop() >> >> Is this the right way to do things, or would you suggest something different? >> >> Thanks, >> Chris >> > Using Tkinter.Toplevel may be better. :) > -- > http://mail.python.org/mailman/listinfo/python-list I thought that would be a good idea, so I changed the code a bit to this: from Tkinter import * class Net: def __init__(self): self.window = Toplevel() def show(self,t): self.l = Label(self.window,text=t) self.l.grid() button = Button(self.window, text="Again") button.bind("<Button-1>", self.Again) button2 = Button(self.window, text="Dismiss") button2.bind("<Button-1>", self.window.destroy) button.grid() button2.grid() def Again(self,event): x = Net() x.show("window 3") root = Tk() root.title = "test" f = Frame(root,bg="Yellow") l = Label(f,text="window 1") f.grid() l.grid() x = Net() x.show("window 2") if __name__ == "__main__": root.mainloop() I put the call to Topevel into the Class. This however, gets me an error message Traceback (most recent call last): File "a.py", line 27, in <module> x = Net() File "a.py", line 5, in __init__ self.window = Toplevel() File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 1978, in __init__ self.title(root.title()) TypeError: 'str' object is not callable I should think it would work, but I don't understand why it doesn't. Thanks
From: Peter Otten on 2 Aug 2010 08:25 Chris Hare wrote: >>> root = Tk() >>> root.title = "test" > I should think it would work, but I don't understand why it doesn't. Try root.title("test") title() is a method that you are hiding with your attribute leading to problems later on. By the way, what kind of documentation are you using for your efforts? Here's a concise one: http://infohost.nmt.edu/tcc/help/lang/python/tkinter.html Also, effbot.org has a lot of information that you best access via Google. Peter
From: Chris Hare on 2 Aug 2010 08:49 On Aug 2, 2010, at 7:25 AM, Peter Otten wrote: > Chris Hare wrote: > >>>> root = Tk() >>>> root.title = "test" > >> I should think it would work, but I don't understand why it doesn't. > > Try > > root.title("test") > > title() is a method that you are hiding with your attribute leading to > problems later on. > > By the way, what kind of documentation are you using for your efforts? > > Here's a concise one: > > http://infohost.nmt.edu/tcc/help/lang/python/tkinter.html > > Also, effbot.org has a lot of information that you best access via Google. > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list I have several python books and I have been using effbot and various other sources. Thanks for the help. Your suggestion (and a couple others I added) got my example working exactly like I want it, so I can incorporate that into my program. Thanks again. Chris
|
Pages: 1 Prev: exception handling with sqlite db errors Next: Why is python not written in C++ ? |