making widgets invisible

Jerome Quelin jerome.quelin at insalien.org
Mon Jul 3 11:28:30 EDT 2000


Thomas Thiele <thiele at muc.das-werk.de> wrote:
>No I think this is not sooo nice. Becouse I want to replace the widget
>with others.
What about the pack_forget method ?

-- File pack_forget.py
#!/usr/bin/python
from Tkinter import *
class F(Frame):
    def __init__(self):
        Frame.__init__(self)
        Button(self,text='change', command=self.change).pack()
        self.f1 = Frame(self)
        self.f2 = Frame(self)
        Label(self.f1, text='eggs', bg='red').pack(side=LEFT)
        Label(self.f1, text='spam', bg='green').pack(side=LEFT)
        Label(self.f2, text='spam', bg='blue').pack(side=LEFT)
        Label(self.f2, text='eggs', bg='yellow').pack(side=LEFT)
        self.f1.pack()
        self.visible = 1
        self.pack()
    def change(self):
        if self.visible == 1:
            self.f1.pack_forget()
            self.f2.pack()
            self.visible = 2
        else:
            self.f2.pack_forget()
            self.f1.pack()
            self.visible = 1
F().mainloop()
-- End of file

The beauty of pack_forget is that it just unmaps the specified widget, and
keeps the internal layout of the widget.

 Regards,
Jerome
--
jerome.quelin at insalien.org



More information about the Python-list mailing list