[Tkinter-discuss] Adding/removing widgets from a running application?

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Thu Feb 14 08:29:02 CET 2008

Russell E. Owen wrote:
> In article <foqjpn$eff$1 at ger.gmane.org>,
>  Alexander Belchenko <bialix at ukr.net> wrote:
>> Hash: SHA1
>> Jim Kleckner пишет:
>> | Any pointers to what it takes to add/remove widgets
>> | from a running application?
>> Something like this maybe?
>> from Tkinter import *
>> root = Tk()
>> x = Label(root, text='Hello')
>> x.pack()
>> Button(root, text='Hide', command=x.pack_forget).pack()
>> root.mainloop()
> Or if you use the gridder you can remove things temporary and restore 
> them again easily:
>   x.grid(row=0....)
>   x.grid_remove() # to temporarily remove
>   x.grid() # to restore using the original grid settings
>   x.grid_forget() # to remove permanently
> (remove is not supported by the packer)

pack_forget does not erm remove either ;)

from Tkinter import *

root = Tk()
root.title("Pack is BEST!!!")

l = Label(root, text="Pack is simply the best")

def forget():

def remember():

b = Button(root, text="Forget about it", command=forget)
b = Button(root, text="Wait, I still need you", command=remember)


BUT... the remember function packs the label widget in it's new packing 
order, so it is packed after the two buttons, as far as I know the only
way to 'remember' its pack position is to put it inside a Frame widget
(and leave the Frame where it stands) - at least thats how I do it

To the OP I guess you've seen how easy this is with Tk(inter) :)


More information about the Tkinter-discuss mailing list