Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Collapsible Pane in Tkinter | Python
Next article icon

Tkinter provides numerous of universal widget methods or basic widget methods which works almost with all the available widgets.
 

winfo_ismapped() method -


This method is used to check whether the specified widget is visible or not. However, in this example, right after packing the widget back, the winfo_ismapped() method still returns the widget to be not mapped (false). Only after you clicked the button the second consecutive time it will update to be mapped (True).
 

Syntax: widget.winfo_ismapped()
Return Value: Returns True if widget is visible (or mapped), otherwise returns False.
Exception: If widget is destroyed, then it throws error.


 

Puython
# Imports tkinter and ttk modulefromtkinterimport*fromtkinter.ttkimport*importtime# toplevel windowroot=Tk()defforget(widget):widget.forget()print("After Forget method called. Is widget mapped? = ",bool(widget.winfo_ismapped()))defretrieve(widget):widget.pack()print("After retrieval of widget. Is widget mapped? = ",bool(widget.winfo_ismapped()))# Button widgetsb1=Button(root,text="Btn 1")b1.pack()# This is used to make widget invisibleb2=Button(root,text="Btn 2",command=lambda:forget(b1))b2.pack()# This will retrieve widgetb3=Button(root,text="Btn 3",command=lambda:retrieve(b1))b3.pack()# infinite loop, interrupted by keyboard or mousemainloop()

Output:
 After first Btn 2 Press:

 

After First Btn 3 Press:

 

After Second Btn 3 Press:
 

 


 

winfo_exists() method -


This method is used to check if the specified widget exists or not i.e if the widget is destroyed or not.
 

Syntax: widget.winfo_exists()
Return value: Returns True if widget exists, False otherwise.


 

Python
# Imports tkinter and ttk modulefromtkinterimport*fromtkinter.ttkimport*# toplevel windowroot=Tk()defdest(widget):widget.destroy()print("Destroy method called. Widget exists? = ",bool(widget.winfo_exists()))defexist(widget):print("Checking for existence = ",bool(widget.winfo_exists()))# Button widgetsb1=Button(root,text="Btn 1")b1.pack()# This is used to destroy widgetb2=Button(root,text="Btn 2",command=lambda:dest(b1))b2.pack()# This is used to check existence of the widgetb3=Button(root,text="Btn 3",command=lambda:exist(b1))b3.pack()# infinite loop, interrupted by keyboard or mousemainloop()

Output:
 

winfo_ismapped() method in tkinter 1


 

winfo_ismapped() method in tkinter 2


 

winfo_ismapped() method in tkinter


Note: If a widget is destroyed it cannot be retrieved again.
 


Improve
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp