#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Champaign - Urbana, IL
    Posts
    54
    Rep Power
    10

    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.

    Thanks!
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    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?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Champaign - Urbana, IL
    Posts
    54
    Rep Power
    10
    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?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    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:
    Python Code:
     
    from Tkinter import *
     
    def switch_normal():
        f2.pack_forget()
        f1.pack()
     
    def switch_advanced():
        f1.pack_forget()
        f2.pack()
     
    root = Tk()
     
    Button(text="Switch to Advanced Mode", command=switch_advanced).pack()
    Button(text="Switch to Normal Mode", command=switch_normal).pack()
     
    f1 = Frame()
    f1.pack()
    Label(f1, text="Normal Mode").pack()
     
    f2 = Frame()
    Label(f2, text="Advanced Mode").pack()
     
    root.mainloop()

    If you want to switch just once, then you can use f1.destroy() and f2.destroy().

    Regards, mawe
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Champaign - Urbana, IL
    Posts
    54
    Rep Power
    10
    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.

    Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo