Container Widgets

The Tkinter module supplies widgets whose purpose is to contain other widgets. A Frame instance does nothing more than 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 certain requests). To ensure that a widget parent, which must be a Frame or Toplevel instance, is the parent (also known as master) of another widget child, pass parent as the first parameter when you instantiate child.

Frame

Class Frame represents 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 whatever window manager handles your screen. Each instance of Toplevel can interact with the window manager and can contain other widgets. Every program using Tkinter has at least one top-level window, known as the root window. You can instantiate Tkinter’s root window explicitly using root =Tkinter.Tk( ); otherwise Tkinter instantiates its root window implicitly as and when first needed. If you want to have more ...

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.