A top-level window is a window that has an independent existence under the window manager. It is decorated with the window manager's decorations, and can be moved and resized independently. Your application can use any number of top-level windows.
For any widget
, you
can get to its top-level widget using
w
.w
.winfo_toplevel()
To create a new top-level window:
w
= Toplevel (option
, ... )
Options include:
bg or
background | The background color of the window. See Section 4.3, “Colors”. |
bd or
borderwidth | Border width in pixels; default is
0 . For possible values, see
Section 4.1, “Dimensions”. See also the
relief option,
below. |
class_ | You can give a Toplevel
window a “class” name. Such names are
matched against the option database, so your
application can pick up the user's configuration
preferences (such as colors) by class name. For
example, you might design a series of popups called
“screamers,” and set them all up with
class_="Screamer" . Then you
can put a line in your option database like this:
*Screamer*background: redand then, if you use the .option_readfile() method to
read your option database, all widgets with that
class name will default to a red background. This
option is named class_
because class is a reserved
word in Python. |
cursor | The cursor that appears when the mouse is in this window. See Section 4.8, “Cursors”. |
height | Window height; see Section 4.1, “Dimensions”. |
relief | Normally, a top-level window will have no 3-d
borders around it. To get a shaded border, set the
bd option larger that its
default value of zero, and set the
relief option to one of the
constants discussed under Section 4.6, “Relief styles”. |
width | The desired width of the window; see Section 4.1, “Dimensions”. |
These methods are available for top-level windows:
.aspect (
nmin
,
dmin
,
nmax
,
dmax
)
Constrain the root window's width:length ratio to
the range
[
/
nmin
,
dmin
/
nmax
].dmax
.deiconify()
If this window is iconified, expand it.
.geometry ( newGeometry
=None )
Set the window geometry. For the form of the argument, see Section 4.10, “Geometry strings”. If the argument is omitted, the current geometry string is returned.
.iconify()
Iconify the window.
.lift ( aboveThis
=None )
To raise this window to the top of the stacking
order in the window manager, call this method with
no arguments. You can also raise it to a position
in the stacking order just above another
Toplevel
window by passing
that window as an argument.
.lower ( belowThis
=None )
If the argument is omitted, moves the window to
the bottom of the stacking order in the window
manager. You can also move the window to a position
just under some other top-level window by passing
that Toplevel
widget as an
argument.
.maxsize ( width
=None, height
=None )
Set the maximum window size. If the arguments
are omitted, returns the current (width,
height)
.
.minsize (
width
=None,
height
=None )
Set the minimum window size. If the arguments are omitted, returns the current minima as a 2-tuple.
.resizable (
width
=None,
height
=None )
If
is true, allow horizontal resizing. If
width
is true, allow vertical resizing. If the arguments
are omitted, returns the current size as a
2-tuple.height
.title (
text
=None
)
Set the window title. If the argument is omitted, returns the current title.
.withdraw()
Hides the window. Restore it with
.deiconify()
or
.iconify()
.