toplevel(3tk)
okay bestie, welcome to toplevel(3tk) β straight out of the Tk Built-In Commands collection. pull up a chair, grab a lil snack, because we're about to make windows. πͺβ¨
π NAME π
toplevel β the command that creates and manipulates 'toplevel' main and popup window widgets. she makes windows, she runs the place, she's the main character of your whole GUI. π
β¨ SYNOPSIS β¨
toplevel pathName ?options?
that's it. that's the whole summoning ritual. π―οΈ
π STANDARD OPTIONS π
these are the classic, the icons, the ones every well-behaved widget shows up with:
-borderwidth-cursor-highlightbackground-highlightcolor-highlightthickness-padx-pady-relief-takefocus
for the full tea on these, go read the options manual entry β she spills all the details. π
π¦ WIDGET-SPECIFIC OPTIONS π¦
these are the options that are hers, yk? the ones that make a toplevel a toplevel. π
-background- Database Name:
background - Database Class:
Background
- Database Name:
literally the same as the standard -background option except β plot twist β its value can also be an empty string. and if you do that? the widget shows no background or border, and no colors get consumed from its colormap for its background and border. also, an empty background will disable drawing the -backgroundimage. π«₯
-backgroundimage- Database Name:
backgroundImage - Database Class:
BackgroundImage
- Database Name:
this one says "here's an image to display on the toplevel's background," drawn within the border of the toplevel β so yes, the image gets clipped by the toplevel's highlight ring and border, if either of those are present β and it goes on top of the background. subwidgets of the toplevel will be drawn on top of it. π
the image must have been created with the image create command. if you specify it as the empty string, no image will be displayed. bye image. π
-class- Database Name:
class - Database Class:
Class
- Database Name:
sets a class for the window. this class gets used when you query the option database for the window's other options, and it also gets used later for other purposes like bindings. some window managers show the class name for windows in their dock, and some others show the window title instead. heads up: the -class option may not be changed with the configure widget command. periodt. π«
-colormap- Database Name:
colormap - Database Class:
Colormap
- Database Name:
picks a colormap for the window. the value can be either new β in which case a brand new colormap is created for the window and its children β or the name of another window, in which case that window must be on the same screen and have the same visual as pathName, and your new window will use the colormap from that specified window. if -colormap isn't specified at all, the new window just uses the default colormap of its screen. and nope, this option may not be changed with the configure widget command. π
-container- Database Name:
container - Database Class:
Container
- Database Name:
value must be a boolean. if true, it means this window is being used as a container that some other application gets embedded into (for example, a Tk toplevel can be embedded using the -use option π«). the window will support the appropriate window manager protocols for stuff like geometry requests. in that case the window should not have any children of its own in this application. also locked: this option may not be changed with the configure widget command. π
-height- Database Name:
height - Database Class:
Height
- Database Name:
the desired height for the window, in any of the forms acceptable to Tk_GetPixels. if this option is negative or zero, the window won't request any size at all. she's unbothered, moisturized, size-agnostic. π§
-menu- Database Name:
menu - Database Class:
Menu
- Database Name:
names a menu widget to be used as a menubar.
- on the Macintosh, the menubar will be displayed across the top of the main monitor. π
- on Microsoft Windows and all UNIX platforms, the menu will appear across the toplevel window as part of the window dressing maintained by the window manager. πͺ
-screen- Database Name: (none)
- Database Class: (none)
specifies the screen on which to place the new window. any valid screen name works, even one associated with a different display. defaults to the same screen as its parent. this option is special, bestie: it may not be specified via the option database, and it may not be modified with the configure widget command. she's built different. β¨
-tile- Database Name:
tile - Database Class:
Tile
- Database Name:
controls how to draw the background image (see -backgroundimage) on the toplevel.
- if true (according to
Tcl_GetBoolean), the image gets tiled to fill the whole toplevel, with the origin of the first copy of the image being the top left of the interior of the toplevel. π§© - if false β which is the default β the image gets centered within the toplevel. π―
-use- Database Name:
use - Database Class:
Use
- Database Name:
this one's for embedding. if the value isn't an empty string, it must be the window identifier of a container window, specified as a hexadecimal string like the ones returned by the winfo id command. the toplevel widget will then be created as a child of the given container instead of the root window for the screen. π±
if the container window is inside a Tk application, it must be a frame or toplevel widget for which the -container option was specified. and ofc, this option may not be changed with the configure widget command. π
-visual- Database Name:
visual - Database Class:
Visual
- Database Name:
specifies visual information for the new window, in any of the forms accepted by Tk_GetVisual. if you don't specify it, the new window uses the default visual for its screen. and yup, the -visual option may not be modified with the configure widget command. π
-width- Database Name:
width - Database Class:
Width
- Database Name:
the desired width for the window, in any of the forms acceptable to Tk_GetPixels. if this option is negative or zero, the window won't request any size at all. again: zero thoughts, zero requests. π
π DESCRIPTION π
the toplevel command creates a new toplevel widget (given by the pathName argument). additional options, described above, may be specified on the command line or in the option database to configure aspects of the toplevel β stuff like its background color and relief. and the toplevel command returns the path name of the new window. π«Ά
a toplevel is basically like a frame, except that it's created as a top-level window: its X parent is the root window of a screen rather than the logical parent from its Tk path name. very "I live alone, I pay my own rent" energy. π
the primary purpose of a toplevel is to serve as a container for dialog boxes and other collections of widgets. the only visible features of a toplevel are its background and an optional 3-D border that makes the toplevel appear raised or sunken. that's the whole lewk. π
π WIDGET COMMAND π
the toplevel command creates a new Tcl command whose name is the same as the path name of the toplevel's window. you use that command to invoke various operations on the widget. general form:
pathName option ?arg ...?
PathName is the name of the command, which is the same as the toplevel widget's path name. Option and the args decide the exact behavior of the command. here's what toplevel widgets can do:
pathName cget optionreturns the current value of the configuration option given by option. option may have any of the values accepted by thetoplevelcommand. peek, don't touch. πpathName configure ?option? ?value option value ...?query or modify the configuration options of the widget. let's break it down:- if no option is specified, it returns a list describing all the available options for pathName (see
Tk_ConfigureInfofor info on the format of this list). - if option is specified with no value, the command returns a list describing that one named option β and this list will be identical to the corresponding sublist of the value returned when no option is specified.
- if one or more option-value pairs are specified, the command modifies the given widget option(s) to have the given value(s); in that case the command returns an empty string.
- if no option is specified, it returns a list describing all the available options for pathName (see
option may have any of the values accepted by the toplevel command. β¨
πΈ BINDINGS πΈ
when a new toplevel is created, it has no default event bindings: toplevels are not intended to be interactive. she's decorative. she's a vessel. she holds your widgets and she does not want to be clicked. π«₯
be aware that bindings on toplevels may receive events from subwidgets. π yes bestie, the events travel. iykyk.
π SEE ALSO π
go read those next, they're the friend group. π«
β KEYWORDS β
toplevel, widget
and that's the whole page, bestie!! this was the Tk 8.4 version of toplevel(3tk) π now go forth and make windows that slay, and remember β every toplevel is somebody's main character. mwah. ππ¦β¨
π¦ where this page comes from
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1990-1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms