newbie question about forms in tkinter

Eamon Reyn eamonreyn at clear.net.nz
Sun Apr 27 05:41:58 EDT 2003


Hi All,

Usually I can find the data I want doing a google group search (kudos to you
guys for having such good answers to most peoples questions) but in this
case I have run into a bit of a wall.

I am creating a little app which needs to have multiple forms pop up but
whenever I try to create a second form in my application the content I want
to appear on the new form just gets placed into my existing one. Here is som
sample code which looks vaguely sane to me but can someone please tell me
what is wrong with it.

from Tkinter import *

class Interface2(Frame):
    def __init__(self, master = None):
        Frame.__init__(self, master)

        # Put the objects on the window
        self.createObjects()
        self.pack()

    def createObjects(self):
        self.lbltest=Label(self)
        self.lbltest.grid(row=0, col=0)
        self.lbltest["text"]="On an new form"


class Interface(Frame):
    def __init__(self, master = None):
        Frame.__init__(self, master)

        # Put the objects on the window
        self.createObjects()
        self.pack()

    def createObjects(self):
        self.b=Button(self, text="create form")
        self.b.grid(row=0, col=0)
        self.b["command"]=self.newForm

    def newForm(self):
        myInter2 = Interface2()
        myInter2.mainloop();

if __name__ == "__main__":
    myInter = Interface()
    myInter.master.title("Test app")
    myInter.mainloop()

Thanks in advance
Eamon.







More information about the Python-list mailing list