Tkinter Toplevel

The Toplevel widget is used to create and display the toplevel windows which are directly managed by the window manager. The toplevel widget may or may not have the parent window on the top of them.

The toplevel widget is used when a python application needs to represent some extra information, pop-up, or the group of widgets on the new window.

The toplevel windows have the title bars, borders, and other window decorations.

The syntax to use the Toplevel widget is given below.

Syntax

A List of possible options is given below.

SNOptionsDescription
1bgIt represents the background color of the window.
2bdIt represents the border size of the window.
3cursorThe mouse pointer is changed to the cursor type set to the arrow, dot, etc. when the mouse is in the window.
4class_The text selected in the text widget is exported to be selected to the window manager. We can set this to 0 to make this behavior false.
5fontThe font type of the text inserted into the widget.
6fgThe foreground color of the widget.
7heightIt represents the height of the window.
8reliefIt represents the type of the window.
9widthIt represents the width of the window,

Methods

The methods associated with the Toplevel widget is given in the following list.

SNMethodDescription
1deiconify()This method is used to display the window.
2frame()It is used to show a system dependent window identifier.
3group(window)It is used to add this window to the specified window group.
4iconify()It is used to convert the toplevel window into an icon.
5protocol(name, function)It is used to mention a function which will be called for the specific protocol.
6state()It is used to get the current state of the window. Possible values are normal, iconic, withdrawn, and icon.
7transient([master])It is used to convert this window to a transient window (temporary).
8withdraw()It is used to delete the window but doesn't destroy it.
9maxsize(width, height)It is used to declare the maximum size for the window.
10minsize(width, height)It is used to declare the minimum size for the window.
11positionfrom(who)It is used to define the position controller.
12resizable(width, height)It is used to control whether the window can be resizable or not.
13sizefrom(who)It is used to define the size controller.
14title(string)It is used to define the title for the window.

Example

Output:

Python Tkinter Toplevel



Latest Courses