Tkinter: Frames in nested classes?

Joshua Weage weage98 at yahoo.com
Fri Jul 13 10:16:44 EDT 2001


I'm trying to nest frames inside of other frames, hiding the detatils
inside of a class - the purpose is to be able to change a child frame,
depending on the options selected in the parent.  When I don't use
classes the frames nest as expected - but the program wouldn't be as
clean.  When I attempt to use classes, the frames are packed
individually into root.

The labels correctly use 'self' as the master, and are placed inside
of the frames, but the child frames appear to use 'root' instead of
'self' as the master.


Here is a simple example:

from Tkinter import *

class Frame1(Frame):
        def __init__(self,master=None,cnf={},**kw):
                Frame.__init__(self,master=None,cnf={},**kw)
                Label(self,text="frame1").pack()
                self.frame =
Frame2(self,borderwidth=5,relief="groove")
                self.frame.pack()

class Frame2(Frame):
        def __init__(self,master=None,cnf={},**kw):
                Frame.__init__(self,master=None,cnf={},**kw)
                Label(self,text="frame2").pack()
                self.frame =
Frame3(self,borderwidth=5,relief="groove")
                self.frame.pack()

class Frame3(Frame):
        def __init__(self,master=None,cnf={},**kw):
                Frame.__init__(self,master=None,cnf={},**kw)
                Label(self,text="testing").pack()

root = Tk()

root.title("Temp testing")
root.config(height=200,width=300)

frame1 = Frame1(root,borderwidth=5,relief="groove")
frame1.pack()

root.mainloop()



More information about the Python-list mailing list