[Tutor] Multiple Tk frames

Alan Gauld alan.gauld at btinternet.com
Tue Feb 13 22:49:16 CET 2007

"Hazlett, Les" <les.hazlett at navteq.com> wrote

> I have found many simple examples of using Tk with one frame.
> I found self.quit to close the open frame object.
> I see that control goes to the end of main, but I don't know
> how to then create and use another frame.

You first need to get your terminology straight. A Frame
is a container widget in Tk and as such you normally have
many, many frames - even inside a single window!

>From looking at your code below you want to close a
window then open another one. Without the user doing
anything - thats a very unusual GUI! Are you sure you
want the second window to open after you close the first?
Are you sure you don;t want the second window (a dialog
maybe?) to open as the first closes - that would be
more common. (In which case look at the TopLevel widget.

But GUI programs are event driven, they rely on a single
event loop dispatching messages(events) to the application.
You need to structure your code around that concept. Which
object will receive the messages? Which object creates
windows/dialogs etc?

Actually from your code it looks like you may be searching
for the tk file dialogs that do the usual file open, file saveas
fuinctions. If that is the case ask us again in terms of what
you are really trying to do. ;-)


Alan Gauld
Author of the Learn to Program web site


# Test using TK

from Tkinter import *

class Window1(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)

    def create_widgets(self):
     # create a quit button
               text = "Quit",
               command = self.quit
               ).grid(row = 10, column = 1)

# main
root = Tk()
root.title("Portable Disk Upload")
app = Window1(root)

print '\nWanted to stop here and do it again.'

root = Tk()
root.title("Select Source Directory")
app = Window1(root)

The information contained in this communication may be CONFIDENTIAL 
and is intended only for the use of the recipient(s) named above. If 
you are not the intended recipient, you are hereby notified that any 
dissemination, distribution, or copying of this communication, or any 
of its contents, is strictly prohibited. If you have received this 
communication in error, please notify the sender and delete/destroy 
the original message and any copy of it from your computer or paper 


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list