toplevel
Guide: Frames, labels, and buttons
Makes a toplevel: a widget with a window of its own on the desktop.
toplevel PATHNAME ?OPTION VALUE ...?
Description
Makes a toplevel widget with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. A toplevel is a frame in a platform window of its own. wm sets its title, its size, and its other properties, and destroy closes it. The main window . is a toplevel too.
The parent of PATHNAME must exist, and PATHNAME must not. The title of the new window is the last part of the path name. A toplevel is a Toplevel in CSS and for the option database, unless -class gives it another class.
-class, -colormap, -container, -screen, -use, and -visual take a value only at the creation of the toplevel. configure of one of them gives an error. On the web, a second toplevel has no canvas of its own.
Widget commands
| Command | Description |
|---|---|
toplevel cget | Gives the value of an option of the toplevel. |
toplevel configure | Gives or sets the options of the toplevel. |
Options
| Option | Type | Default | Database name | Description |
|---|---|---|---|---|
-borderwidth | screen distance | 0 | borderWidth | The width of the border of the toplevel. |
-class | string | Toplevel | class | The class of the toplevel for the option database and for bind. |
-menu | widget path name | empty | menu | The menu bar of the toplevel. |
-relief | relief | flat | relief | The 3-D look of the border. |
-screen | string | empty | screen | The X11 display and screen of the toplevel. |
-use | string | empty | use | The ID of a window of another application to embed the toplevel in. |
-background | color | #d9d9d9 | background | The background color of the toplevel. |
-colormap | string | empty | colormap | The colormap of the toplevel, a feature of X11. |
-container | boolean | 0 | container | Whether the toplevel holds the window of another application, a feature of X11. |
-cursor | cursor name | empty | cursor | The shape of the pointer over the toplevel. |
-height | screen distance | 0 | height | The height that the toplevel asks for. |
-highlightbackground | color | #d9d9d9 | highlightBackground | The color of the focus ring while the toplevel has no focus, in the look of Tk on X11. |
-highlightcolor | color | #000000 | highlightColor | The color of the focus ring while the toplevel has the focus, in the look of Tk on X11. |
-highlightthickness | screen distance | 0 | highlightThickness | The width of the focus ring, in the look of Tk on X11. |
-padx | screen distance | 0 | padX | The space between the left and the right sides of the toplevel and its children. |
-pady | screen distance | 0 | padY | The space between the top and the bottom of the toplevel and its children. |
-takefocus | string | 0 | takeFocus | Whether the Tab key can move the focus to the toplevel. |
-visual | string | empty | visual | The visual of the toplevel, a feature of X11. |
-width | screen distance | 0 | width | The width that the toplevel asks for. |
-borderwidth DISTANCE
The width of the border of the toplevel.
The width of the border around the toplevel. -bd is the same option. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.
% toplevel .borderwidth -borderwidth 4
> .borderwidth cget -borderwidth
4% toplevel .borderwidth2 -borderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS-class TEXT
The class of the toplevel for the option database and for bind.
The class name that winfo class gives. The option database and the bindings of the class use it. Set it only at the creation of the toplevel.
% toplevel .class -class Panel
> winfo class .class
Panel% toplevel .class2; .class2 configure -class Other
can't modify -class option after widget is created
-errorcode NONE-menu MENU
The menu bar of the toplevel.
The path name of a menu widget. The toplevel shows the entries of the menu as its menu bar. On macOS and Windows the bar is the menu bar of the system. On the other platforms ztk renders the bar at the top of the toplevel, and winfo height includes it. An empty value removes the bar.
% menu .menubar
> .menubar add command -label Quit
> toplevel .menu -menu .menubar
> .menu cget -menu
.menubarztk stores each value with no check, as Tk 8.6.16 does.
-relief RELIEF
The 3-D look of the border.
Each value side by side: the contact sheet of the reliefs
The style of the border: raised and sunken look 3-D, and groove and ridge are lines. The theme draws the border, and the CSS of the theme can give a relief its own look with border-style.
Values: flat, groove, raised, ridge, solid, sunken.
% toplevel .relief -relief groove
> .relief cget -relief
groove% toplevel .relief2 -relief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy-screen SCREEN
The X11 display and screen of the toplevel.
In Tk on X11, the value names the display of the new window, such as :0. Set it only at the creation of the toplevel. ztk stores the value with no effect, and the toplevel opens on the display of the application.
% toplevel .screen -screen {}
> .screen cget -screen% toplevel .screen2; .screen2 configure -screen :0
can't modify -screen option after widget is created
-errorcode NONE-use WINDOW
The ID of a window of another application to embed the toplevel in.
In Tk, the toplevel becomes a child of the window with this ID. Set it only at the creation of the toplevel. ztk stores the value with no effect.
% toplevel .use -use {}
> .use cget -use% toplevel .use2; .use2 configure -use 0x10
can't modify -use option after widget is created
-errorcode NONE-background COLOR
The background color of the toplevel.
The color that fills the toplevel. -bg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.
% toplevel .background -background {#336699}
> .background cget -background
#336699% toplevel .background2 -background nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor
# Tk 8.6.16 accepts an empty value and draws no background.
% toplevel .background3 -background {}
unknown color name ""
-errorcode TK LOOKUP COLOR {}-colormap TEXT
The colormap of the toplevel, a feature of X11.
In Tk on X11, new gives the toplevel a colormap of its own. Set it only at the creation of the toplevel. ztk stores the value with no effect.
% toplevel .colormap -colormap new
> .colormap cget -colormap
new% toplevel .colormap2; .colormap2 configure -colormap new
can't modify -colormap option after widget is created
-errorcode NONE-container BOOLEAN
Whether the toplevel holds the window of another application, a feature of X11.
In Tk, a container holds an embedded window of another application. Set it only at the creation of the toplevel. ztk stores the value with no effect.
% toplevel .container -container 0
> .container cget -container
0% toplevel .container2; .container2 configure -container 1
can't modify -container option after widget is created
-errorcode NONE-cursor CURSOR
The shape of the pointer over the toplevel.
Each value side by side: the contact sheet of the cursors
A cursor name of Tk, such as hand2 or xterm. A value that starts with @ names a file. An empty value uses the cursor of the parent.
% toplevel .cursor -cursor hand2
> .cursor cget -cursor
hand2% toplevel .cursor2 -cursor nocursor
bad cursor spec "nocursor"
-errorcode TK VALUE CURSOR-height DISTANCE
The height that the toplevel asks for.
With a geometry manager inside the toplevel, such as pack or grid, the size of the children sets the size of the toplevel, and this option has an effect only after pack propagate or grid propagate is off. 0 asks for no height.
% toplevel .height -height 4
> .height cget -height
4% toplevel .height2 -height x
bad screen distance "x"
-errorcode TK VALUE PIXELS-highlightbackground COLOR
The color of the focus ring while the toplevel has no focus, in the look of Tk on X11.
The color of the highlight ring of -highlightthickness while the toplevel does not have the focus. ztk stores the value with no effect.
% toplevel .highlightbackground -highlightbackground {#336699}
> .highlightbackground cget -highlightbackground
#336699% toplevel .highlightbackground2 -highlightbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-highlightcolor COLOR
The color of the focus ring while the toplevel has the focus, in the look of Tk on X11.
The color of the highlight ring of -highlightthickness while the toplevel has the focus. ztk stores the value with no effect.
% toplevel .highlightcolor -highlightcolor {#336699}
> .highlightcolor cget -highlightcolor
#336699% toplevel .highlightcolor2 -highlightcolor nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-highlightthickness DISTANCE
The width of the focus ring, in the look of Tk on X11.
The width of the ring around the toplevel that shows the focus. The modern theme stores the value with no effect on the size.
% toplevel .highlightthickness -highlightthickness 4
> .highlightthickness cget -highlightthickness
4% toplevel .highlightthickness2 -highlightthickness x
bad screen distance "x"
-errorcode TK VALUE PIXELS-padx DISTANCE
The space between the left and the right sides of the toplevel and its children.
The geometry managers put the children inside this space. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.
% toplevel .padx -padx 4
> .padx cget -padx
4% toplevel .padx2 -padx x
bad screen distance "x"
-errorcode TK VALUE PIXELS-pady DISTANCE
The space between the top and the bottom of the toplevel and its children.
The geometry managers put the children inside this space. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.
% toplevel .pady -pady 4
> .pady cget -pady
4% toplevel .pady2 -pady x
bad screen distance "x"
-errorcode TK VALUE PIXELS-takefocus TEXT
Whether the Tab key can move the focus to the toplevel.
1 puts the toplevel in the order of the Tab key, and 0 leaves it out. An empty value uses the default rule of Tk for the widget. In Tk the value can also be a script, and its result is the answer. ztk stores each value with no check.
% toplevel .takefocus -takefocus 1
> .takefocus cget -takefocus
1ztk stores each value of the option with no check.
-visual TEXT
The visual of the toplevel, a feature of X11.
In Tk on X11, the visual sets the color model of the window. Set it only at the creation of the toplevel. ztk stores the value with no effect.
% toplevel .visual -visual {}
> .visual cget -visual% toplevel .visual2; .visual2 configure -visual best
can't modify -visual option after widget is created
-errorcode NONE-width DISTANCE
The width that the toplevel asks for.
With a geometry manager inside the toplevel, such as pack or grid, the size of the children sets the size of the toplevel, and this option has an effect only after pack propagate or grid propagate is off. 0 asks for no width.
% toplevel .width -width 4
> .width cget -width
4% toplevel .width2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELSReturns
PATHNAME.
Examples
% toplevel .prefs
> wm title .prefs Preferences
> wm title .prefs
Preferences
# The default title is the last part of the path name.
% toplevel .about
> list [winfo toplevel .about] [wm title .about]
.about about
% winfo class [toplevel .go]
Toplevel
Errors
% toplevel .x -foo 1
unknown option "-foo"
-errorcode TK LOOKUP OPTION -foo
% toplevel .twice
> toplevel .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS
# The parent .no does not exist.
% toplevel .no.b
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no
% toplevel
wrong # args: should be "toplevel pathName ?-option value ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
-useaccepts any value, and the toplevel is not embedded. Tk 8.6.16 gives the errorcouldn't create child of windowfor an ID that is not a window.-screen,-colormap,-container,-visual,-highlightbackground, and-highlightcolorare stored with no effect.-highlightthicknesshas no effect on the size.- An empty
-backgroundgives the errorunknown color name "". In Tk 8.6.16 an empty value is valid. - The error of a change of a create-only option after the creation has the
-errorcodeNONE. Tk 8.6.16 givesTK FRAME CREATE_ONLY. - The menu bar that ztk renders on Linux and the web is part of the toplevel, so
winfo heightof the toplevel includes the bar.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1