The Tkinter Toplevel Widget
The Toplevel widget work pretty much like Frame, but it is displayed in a separate, top-level window. Such windows usually have title bars, borders, and other “window decorations”.
When to use the Toplevel Widget
The Toplevel widget is used to display extra application windows, dialogs, and other “pop-up” windows.
... top = Toplevel() top.title("About this application...") msg = Message(top, text=about_message) msg.pack() button = Button(top, text="Dismiss", command=top.destroy) button.pack()
FIXME: add more patterns
- Toplevel(master=None, **options) (class) [#]
A widget container placed in a new top level window.
- Parent widget.
- Widget options. See the description of the config method for a list of available options.
- config(**options) [#]
Modifies one or more widget options. If no options are given, the method returns a dictionary containing all current option values.
- Widget options.
- The background color to use in this toplevel. This defaults to the application background color. To prevent updates, set the color to an empty string. (the option database name is background, the class is Background)
- Same as background.
- Width of the 3D border. Defaults to 0 (no border). (borderWidth/BorderWidth)
- Same as borderwidth.
- Default value is Toplevel. (class/Class)
Some displays support only 256 colors
(some use even less). Such displays usually provide a
color map to specify which 256 colors to use. This
option allows you to specify which color map to use
for this toplevel window, and its child widgets.
By default, a new toplevel window uses the same color map as the root window. Using this option, you can reuse the color map of another window instead (this window must be on the same screen and have the same visual characteristics). You can also use the value “new” to allocate a new color map for this window.
You cannot change this option once you’ve created the window. (colormap/Colormap)
- Default value is 0. (container/Container)
- The cursor to show when the mouse pointer is located over the toplevel widget. Default is a system specific arrow cursor. (cursor/Cursor)
- Window height, in pixels. If omitted, the widget is made large enough to hold its contents. (height/Height)
- The color to use for the highlight region when the widget doesn’t have focus. The default is system specific. (highlightBackground/HighlightBackground)
- The color to use for the highlight region when the widget has focus. The default is system specific. (highlightColor/HighlightColor)
- The width of the highlight region. Default is 0 (no region). (highlightThickness/HighlightThickness)
- A menu to associate with this toplevel window. On Unix and Windows, the menu is placed at the top of the toplevel window itself. On Macs, the menu is displayed at the top of the screen when the toplevel window is selected. (menu/Menu)
- Horizontal padding. Default is 0. (padX/Pad)
- Vertical padding. Default is 0. (padY/Pad)
- Border decoration: either FLAT, SUNKEN, RAISED, GROOVE, or RIDGE. The default is FLAT. (relief/Relief)
- No default value. (screen/Screen)
- Indicates that the user can use the Tab key to move to this widget. Default is false. (takeFocus/TakeFocus)
- No default value. (use/Use)
Controls the “visual” type to use for this
window. This option should usually be omitted. In that
case, the visual type is inherited from the root window.
Some more advanced displays support “mixed visuals”. This typically means that the root window is a 256-color display (the “pseudocolor” visual type), but that individual windows can be displayed as true 24-bit color (the “truecolor” visual type). On such displays, you may wish to explicitly set the visual option to “truecolor” for any windows used to display full-color images.
Other possible values include “directcolor”, “staticcolor”, “grayscale”, or “staticgray”. See your X window documentation for details.
You cannot change this option once you’ve created the window. (visual/Visual)
- Window width, in pixels. If omitted, the widget is made large enough to hold its contents.