Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python Tkinter - ListBox Widget
Next article icon
Tkinter is a GUI (Graphical User interface) module which is used to create various types of applications. It comes along with the Python and consists of various types of widgets which can be used to make GUI more attractive and user-friendly.Checkbutton is one of the widgets which is used to select multiple options.Checkbutton can be created as follows:
chkbtn = ttk.Checkbutton(parent, value = options, ...)
Code #1:Python3 1==
# This will import tkinter and ttkfromtkinterimport*fromtkinterimportttkroot=Tk()# This will set the geometry to 200x100root.geometry('200x100')text1=StringVar()text2=StringVar()# These text are used to set initial# values of Checkbutton to offtext1.set('OFF')text2.set('OFF')chkbtn1=ttk.Checkbutton(root,textvariable=text1,variable=text1,offvalue='GFG Not Selected',onvalue='GFG Selected')chkbtn1.pack(side=TOP,pady=10)chkbtn2=ttk.Checkbutton(root,textvariable=text2,variable=text2,offvalue='GFG Average',onvalue='GFG Good')chkbtn2.pack(side=TOP,pady=10)root.mainloop()
Output #1: When you run application you see the initial states ofCheckbutton as shown in output.Output #2: As soon as youselect theCheckbutton you'll see that text has been changed as in output.Output #3: When youdeselect theCheckbutton you'll again observe following changes.Code #2: Commands can be integrate with theCheckbutton which can be execute when checkbutton is selected or deselected depending upon conditions.Python3 1==
# Importing tkinter, ttk and# _show method to display# pop-up message windowfromtkinterimport*fromtkinterimportttkfromtkinter.messageboximport_showroot=Tk()root.geometry('200x100')text1=StringVar()text1.set('OFF')# This function is used to display# the pop-up messagedefshow(event):string=event.get()_show('Message','You selected '+string)chkbtn1=ttk.Checkbutton(root,textvariable=text1,variable=text1,offvalue='GFG Good',onvalue='GFG Great',command=lambda:show(text1))chkbtn1.pack(side=TOP,pady=10)root.mainloop()
Output:Note: In above codeoffvalue andonvalue are used to set the values ofCheckbutton of non-selected state and selected state respectively.

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