O'Reilly logo

Python in a Nutshell, 2nd Edition by Alex Martelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Container Widgets

The Tkinter module supplies widgets whose purpose is to contain other widgets. A Frame instance does nothing else but act as a container. A Toplevel instance (including Tkinter’s root window, also known as the application’s main window) is a top-level window, so your window manager interacts with it (typically by supplying suitable decoration and handling requests). To ensure that a widget parent, which must be a Frame or Toplevel instance, is the parent (a.k.a. the master) of another widget child, pass parent as the first parameter when you instantiate child.

Frame

Class Frame is a rectangular area of the screen contained in other frames or top-level windows. Frame’s only purpose is to contain other widgets. Option borderwidth defaults to 0, so an instance of Frame normally displays no border. You can configure the option with borderwidth=1 if you want the frame border’s outline to be visible.

Toplevel

Class Toplevel represents a rectangular area of the screen that is a top-level window and therefore receives decoration from whichever window manager handles your screen. Each instance of Toplevel interacts with the window manager and contains other widgets. Every Tkinter program has at least one top-level window, known as the root window. Instantiate Tkinter’s root window with root=Tkinter.Tk( ); otherwise, Tkinter instantiates its root window implicitly as and when it is first needed. If you want more than one top-level window, instantiate the main one with root

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required