Starting a Frame dependent on destruction of another Frame...

Rob Neely rneely at home.com
Mon Jul 16 02:32:10 EDT 2001


I have a simple problem I'm trying to solve with Tkinter.

When my application runs, I want a frame to pop up asking the user for
some info (a directory name).  When they hit the "OK" button, I want
that frame to destroy itself, and start up another toplevel frame
which will be populated with some widgets based on what was entered in
the first frame.

I've enclosed a very stripped down example below.  If you run this
program in linux (under KDE), the only way to get to the second frame
is to close the window with the window manager (ie - clicking the "x"
in the KDE window decorations).  When I run it from MS-windows - even
that doesn't work...

Can anyone show me how I might configure the following applet so
clicking the "OK" button will destroy the frame and start up the next
frame?  Or more generally - how should one set up an application where
one frame is started only after another has destroyed itself.

I've tried as many combinations that I can think of - and this is the
closest I've gotten!

Thanks in advance!

--Rob

from Tkinter import *

class Splash(Frame):
    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        b = Button(self, text="OK", command=self.splash_done)
        b.pack()
        self.pack()
    
    def splash_done(self):
        print "Clicked OK"
        self.destroy()

class Mainapp(Frame):
    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        l = Label(self, text="Main frame opened")
        l.pack()
        self.pack()

Splash().mainloop()
Mainapp().mainloop()



More information about the Python-list mailing list