Re: Tkinter widgets into classes.
Am 01.02.14 20:43, schrieb Lewis Wood: I was wandering if I could dynamically change my GUI and after a few searches on Google found the grid_remove() function. What I'm wandering now is if there is a way to group a lot of widgets up into one, and then use the one grid_remove function which will remove them all. Is it possible to do this in a class like this? class group1: label1=Label(text=Upon clicking the button).grid(row=0,column=0) label2=Label(text=The menu will dynamically change).grid(row=1,column=0) group1.grid_remove() Well, you are on the right track, it is a good idea to structure a complex GUI by breaking it up into smaller functional pieces. The right way to do it is called megawidget, and it's done by making a Frame which contains the subwidgets; e.g. = import Tkinter as Tk import ttk # python3: # import tkinter as Tk # from tkinter import ttk class dbllabel(ttk.Frame): def __init__(self, parent, text1, text2): ttk.Frame.__init__(self, parent) # python3: # super(dbllabel, self).__init__(self, parent) self.l1=ttk.Label(self, text=text1) self.l2=ttk.Label(self, text=text2) self.l1.grid(row=0, column=0) self.l2.grid(row=1, column=0) # now use the dbllabel in our program # like a regular widget root=Tk.Tk() mainframe = ttk.Frame(root) mainframe.pack(expand=True, fill=Tk.BOTH) # here is no difference between making a button # and our fresh new megawidget foo=ttk.Button(mainframe, text=Some other widet) bar=dbllabel(mainframe, text1=First line, text2=Second line) foo.grid(row=0, column=0) bar.grid(row=0, column=1) root.mainloop() Note that 1) I only have python2 to test it here now, so there might be an error on the python3 parts 2) I've used ttk widgets all over where possible. This should give the most expected look and feel on all platforms 3) More complex megawidgets will of course also group functionality (i.e. reactions to button clicks etc.) in the same megawidget class Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
Am 02.02.14 00:07, schrieb Lewis Wood: It does, this is the whole code: from tkinter import * root=Tk() root.title(Second Root Testing) def secondwindow(): root2=Tk() root2.mainloop() button1=Button(root,text=Root2,command=secondwindow).grid(row=0,column=0) root.mainloop() I don't know how this works, but it is definitely wrong. If you need more than one window, use Toplevel() to create it. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
Thanks all who replied, will look further into megawidgets and the Toplevel() function. Is there a way to get a separate window to return something when closed? -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
I just happened to find this link: http://effbot.org/tkinterbook/ through this link: https://wiki.python.org/moin/TkInter which ALL happened to stem from this link: https://www.google.com/search?client=ubuntuchannel=fsq=python+tkinter+tutorialsie=utf-8oe=utf-8 On Sun, Feb 2, 2014 at 3:38 PM, Lewis Wood fluttershy...@gmail.com wrote: Thanks all who replied, will look further into megawidgets and the Toplevel() function. Is there a way to get a separate window to return something when closed? -- https://mail.python.org/mailman/listinfo/python-list -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com http://www.hitwebdevelopment.com* -- https://mail.python.org/mailman/listinfo/python-list
Tkinter widgets into classes.
I was wandering if I could dynamically change my GUI and after a few searches on Google found the grid_remove() function. What I'm wandering now is if there is a way to group a lot of widgets up into one, and then use the one grid_remove function which will remove them all. Is it possible to do this in a class like this? class group1: label1=Label(text=Upon clicking the button).grid(row=0,column=0) label2=Label(text=The menu will dynamically change).grid(row=1,column=0) group1.grid_remove() -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
On Saturday, 1 February 2014 19:43:18 UTC, Lewis Wood wrote: I was wandering if I could dynamically change my GUI and after a few searches on Google found the grid_remove() function. What I'm wandering now is if there is a way to group a lot of widgets up into one, and then use the one grid_remove function which will remove them all. Is it possible to do this in a class like this? class group1: label1=Label(text=Upon clicking the button).grid(row=0,column=0) label2=Label(text=The menu will dynamically change).grid(row=1,column=0) group1.grid_remove() -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
You become less of a a faget and stop sucking granni tranni pussi dis shud help u lewl -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
Oh and another question, say I make another window in the program itself using this: def secondwindow(): root2=Tk() root2.mainloop() Would it be possible for me to use some code which would return True if one of these windows is currently up, or return False if the window is not up? -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
Lewis Wood fluttershy...@gmail.com Wrote in message: Oh and another question, say I make another window in the program itself using this: def secondwindow(): root2=Tk() root2.mainloop() Would it be possible for me to use some code which would return True if one of these windows is currently up, or return False if the window is not up? No need. Only one at a time can be running, and you won't return from this function till it's done. To put it another way, you only want one mainloop in your code. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
On Saturday, 1 February 2014 21:52:51 UTC, Dave Angel wrote: Lewis Wood fluttershy...@gmail.com Wrote in message: Oh and another question, say I make another window in the program itself using this: def secondwindow(): root2=Tk() root2.mainloop() Would it be possible for me to use some code which would return True if one of these windows is currently up, or return False if the window is not up? No need. Only one at a time can be running, and you won't return from this function till it's done. To put it another way, you only want one mainloop in your code. -- DaveA But I can click the button Multiple times and it will create multiple windows? -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
Lewis Wood fluttershy...@gmail.com Wrote in message: (deleting doublespaced googlegroups trash) To put it another way, you only want one mainloop in your code. -- DaveA But I can click the button Multiple times and it will create multiple windows? Not using the function you showed. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
On Saturday, 1 February 2014 22:26:17 UTC, Dave Angel wrote: Lewis Wood fluttershy...@gmail.com Wrote in message: (deleting doublespaced googlegroups trash) To put it another way, you only want one mainloop in your code. -- DaveA But I can click the button Multiple times and it will create multiple windows? Not using the function you showed. -- DaveA It does, this is the whole code: from tkinter import * root=Tk() root.title(Second Root Testing) def secondwindow(): root2=Tk() root2.mainloop() button1=Button(root,text=Root2,command=secondwindow).grid(row=0,column=0) root.mainloop() -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
On Sun, 02 Feb 2014 00:07:00 +0100, Lewis Wood fluttershy...@gmail.com wrote: On Saturday, 1 February 2014 22:26:17 UTC, Dave Angel wrote: Lewis Wood fluttershy...@gmail.com Wrote in message: (snip) DaveA It does, this is the whole code: from tkinter import * root=Tk() root.title(Second Root Testing) def secondwindow(): root2=Tk() root2.mainloop() this may seem to work, but you're starting a new event loop here instead of using the current one. I think you want to create another TopLevel() window here, not a new Tk instance. button1=Button(root,text=Root2,command=secondwindow).grid(row=0,column=0) Note that if you want to be able to actually use the button1 symbol, you have to break this statement up: button1=Button(root,text=Root2,command=secondwindow) button1.grid(row=0,column=0) You can't shortcut this because grid() returns None. root.mainloop() -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter widgets into classes.
Idle, which used tkinter, runs multiple windows in one process with one event loop. There is no reason I know of to run multiple event loops in one process, and if you do, the results will not be documented and might vary between runs or between different systems. Idle can also be run multiple times in multiple processes, each with its own event loop. But there is seldom a reason to do that with the same version. On the other hand, I routinely have more than one version running in order to test code with multiple versions. I can even have the same file open in multiple versions. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list