This tutorial covers the Tkinter Toplevel widget
Tkinter works with a hierarchical system, where there is one root window from where all other widgets and windows expand from. Calling the Tk() function initializes the whole Tkinter application.
Often while creating a GUI, you wish to have more than just one window. Instead of calling the Tk() function again (which is the incorrect way) you should use the Tkinter Toplevel widget instead.
Difference between Tk() and Toplevel()
Calling the Tk() function creates a whole Tkinter instance, while calling the Toplevel() function only creates a window under the root Tkinter instance.
Destroying the Tk() function instance will destroy the whole GUI, whereas destroying the Toplevel() function only destroys that window and it’s child widgets, but not the whole program.
Toplevel syntax
window = Toplevel(options.....)If you have imported Tkinter as “tk” (which is a fairly common approach), you will need to do tk.Toplevel().
Tkinter Toplevel Options
List of all relevant options available for the Toplevel widget.No. Option Description 1 bg Background color for the area around the widget. 2 bd Size of the border around the widget. Default value is 2 pixels. 3 cursor When the mouse is hovering over this widget, it can be changed to a special cursor type like an arrow or dot. 4 font The type of font to be used for this widget. 5 fg The color for the text. 6 height The height of the widget in terms of text lines. 7 relief It specifies the type of the border. Default is Flat, other options include RAISED and SUNKEN.8 width Width of the Checkbutton.
Toplevel Widget Example in Tkinter
This is a simple Toplevel function example simply to demonstrate how it works. Just by calling the TopLevel() Class, a new window will popup, just like when we call Tk().
from tkinter import *
root = Tk()
window = Toplevel()
root.mainloop()
