Toplevel Widget in tkinter
Tkinter Toplevel widget is used to create a new window .
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 widget have same attributes and methods like Tkinter Tk( ) root's .
Syntax :
w = Toplevel(options)
So let's code :
# tkinter : Dynamic Coding # TopLevel ...... # import modules from tkinter import * def func(): # function defination # creating a new window .... top = Toplevel(root) top.geometry('200x150+300+250') # adding widgets to new window .... btn = Button(top,text='new window') btn.pack(anchor=CENTER,pady=50) top.mainloop() root = Tk() root.title("Dynamic Coding") root.geometry('300x250+300+250') root.configure(bg='cyan') # Create button for calling function btn = Button(root,text='Create new window',command=func) btn.pack(anchor=CENTER,pady=100) root.mainloop()
OUTPUT :
List of Toplevel Attributes / options :
bg : It represents the background color of the window.
bd : It represents the border size of the window.
cursor : The mouse pointer is changed to the cursor type set to the arrow, dot, etc. when the mouse is in the window.
class_ : 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.
font : The font type of the text inserted into the widget.
fg : The foreground color of the widget.
height : It represents the height of the window.
relief : It represents the type of the window.
width : It represents the width of the window.
List of Toplevel Methods :
deiconify() : This method is used to display the window.
frame() : It is used to show a system dependent window identifier.
group(window) : It is used to add this window to the specified window group.
iconify() It is used to convert the toplevel window into an icon.
protocol(name, function) : It is used to mention a function which will be called for the specific protocol.
state() : It is used to get the current state of the window. Possible values are normal, iconic, withdrawn, and icon.
transient([master]) : It is used to convert this window to a transient window (temporary).
withdraw() : It is used to delete the window but doesn't destroy it.
maxsize(width, height) : It is used to declare the maximum size for the window.
minsize(width, height) : It is used to declare the minimum size for the window.
positionfrom(who) : It is used to define the position controller.
resizable(width, height) : It is used to control whether the window can be resizable or not.
sizefrom(who) : It is used to define the size controller.
title(string) : It is used to define the title for the window.
This Article is Contributed by Yogesh singh .
Share your suggestions and feedback in comment sections.
Thank you for visiting here ..
No comments