In this tutorial, we will learn about Python Tkinter TopLevel. Tkinter TopLevel is used to show top-level screen and which directly managed by the window manager.
The main motive of showing top-level window is to show extra information on-screen, pop-up or to show a group of widgets in a different window.
Syntax to add Python Tkinter TopLevel:
w = Toplevel(options)
- options: Here is the list of most commonly used options for this widget.
Example Program of Python Tkinter TopLevel:
from tkinter import * mainWindow= Tk() mainWindow.geometry("200x200") def open(): top = Toplevel(mainWindow) top.mainloop() button = Button(mainWindow, text = "open", command = open) button.place(x=75,y=50) mainWindow.mainloop()
Various possible options in Python Tkinter TopLevel:
|bg||This option helps us to set the normal background colour of the window.|
|bd||This option is used to set the size of the border around the widget.|
|cursor||This option helps us to set the style of cursor like an arrow, dot etc|
|font||This option is used to set font type in the widget.|
|fg||This option is used to set the foreground colour widget.|
|height||This helps us to set the height of the window.|
|relief||This helps us to set the type of the window.|
|width||This helps us to set the width of the window.|
Tkinter TopLevel Methods:
After learning about various available options in Python Tkinter TopLevel Its time to check out some available methods for Tkinter TopLevel widget.
|deiconify()||This method is used to display the window on the screen.|
|frame()||This method returns a window identifier which is system-specific.|
|group(window)||This method is used to add a window in the mentioned window group.|
|iconify()||This method is used to turns the window into an icon.|
|protocol(name,function)||This method is used to define a method which can be called for a specific protocol.|
|state()||This method returns the current state of the window.|
|transient(master)||This method is used to convert this window to a transient window.|
|withdraw()||This method is used to remove the window from the screen.|
|maxsize(w,h)||This method is used to define the maximum size of the window(w=width, h=height).|
|minsize(w,h)||This method is used to define the minimum size of the window(w=width, h=height).|
|resizable(w,h)||This method is used to define whether a widow can be resized or not.|
|title(string)||This method is used to set the title for the window.|