Tkinter Toplevel

Normally Tkinter works with a hierarchical system, in which there is one root window to expand other widgets. To solve this issue Tkinte Toplevel. Tkinter Toplevel widgets work as windows which are directly managed by the window manager. Many numbers of Toplevel applications can be used.

Syntax:

The parameter, options are used to set various attribute as key-values separated by commas. The options are described below:

Options of Tkinter Toplevel:

bd: Shows the border width in pixels; By default is 0.

font: Shows the default font for text inserted into the widget.

height: Shows the Window height.

bg: Background color of the window.

width Shows the desired width of the window.

fg: Shows the color used for text within the widget. The color for tagged regions can be changed.

cursor: Shows the appeared cursor when the mouse is in this window.

relief: This option specifies the type of the border. By default is Flat, other options include RAISED and SUNKEN.

Methods of Tkinter Toplevel:

iconify(): This method is used to turns the window into an icon, without destroying it.

deiconify(): This method id used to displays the window, after using either the iconify or the withdraw methods.

title(string): This method defines the title’s window .

state(): This method is used to get the current state of the window. Values can be normal, iconic, withdrawn, and icon.

withdraw(): This method is used to removes the window from the screen, without destroying it.

resizable(width, height): This method used to defines the resize flags, which control whether the window can be resized.

minsize(width, height): This method defines the minimum size for this window.

maxsize(width, height): This method defines the maximum size for this window.

sizefrom(who): This method defines the size controller.

positionfrom(who): This method defines the position controller.

protocol(name, function): This method used to register a function as a callback that will be called for the given protocol.

Example:
from tkinter import *

appWindow = Tk()
appWindow.title("Window Title-Tutorialsart.com")

appWindow.geometry('350x200')


def window_topLevel():
    window1 = Toplevel()
    window1.geometry('150x150')
    label1 = Label(window1, text="ALL PROGRAMS")
    label1.pack()


frame1 = Frame(appWindow)
frame1.pack()

button1 = Button(frame1, text="Click Here", command=window_topLevel, bg="orange")
button1.pack(pady=10)


appWindow.mainloop()
Output:
08 tkinter toplevel

Comments are closed.