September 7th, 2005, 05:25 PM
How to destroy and rebuild an interface?
So, here's a fun one: I build a python program (about which I've asked a few other questions) and now the clients have asked if they could have an "advanced" mode. The normal mode would run and display by default as it does now, but from a pull down menu they could select advanced mode.
When the user does that, I'd need to remove all of the widgets on the screen and then instantiate and create a new, different interface for advanced mode.
How can this be done? I went through the top level controls and frame methods in various Tkinter tutorials around the web but didn't find anything that seemed to be helpful.
September 7th, 2005, 07:08 PM
I'm guessing you don't want the root window to disappear and reappear? Did you try using the del keyword? To delete any Tkinter objects that were formerly created?
September 8th, 2005, 10:38 AM
em to really shut down the GUI it only is possible with destroying the root and then rebluiding it
Those people who think they know everything are a great annoyance to those of us who do.
September 8th, 2005, 04:45 PM
I don't really mind if the window disappears and reappears (hopefully it'll be a short delay) since the interfaces for advanced mode and normal mode will be quite different. Besides, if you open the Microsoft Calculator (those with access to it) and switch from Standard to Scientific view, the interface flickers for a moment before reappearing in the new format. That's exactly what I'm looking to do.
As for deleting previously created Tkinter objects, I don't really have a reference to them, though I could use the top_level window methods to do so. If I delete widgets from the class will the interface's geometry change as those widgets are removed?
September 8th, 2005, 04:57 PM
If you want to switch from normal to advanced mode and back, then pack_forget() (or grid_forget()) might be what you want. Here's a little snippet to show how it works:
from Tkinter import *
root = Tk()
Button(text="Switch to Advanced Mode", command=switch_advanced).pack()
Button(text="Switch to Normal Mode", command=switch_normal).pack()
f1 = Frame()
Label(f1, text="Normal Mode").pack()
f2 = Frame()
Label(f2, text="Advanced Mode").pack()
If you want to switch just once, then you can use f1.destroy() and f2.destroy().
September 9th, 2005, 03:42 PM
Sha-wing. That's it, thanks. I'll have to play around with things a bit to make that happen but the *_forget() functions seem to be what I was looking for.