Answers for "checkbutton state"

0

checkbutton state

import tkinter
 
window_main = tkinter.Tk(className='Tkinter - TutorialKart', )
window_main.geometry("450x250")
 
check_1 = tkinter.IntVar()
check_2 = tkinter.IntVar()
check_3 = tkinter.IntVar()
 
def check1Clicked():
    if check_1.get() :
        print('Checkbox 1 selected')
    else :
        print('Checkbox 1 unselected')
 
def check2Clicked():
    if check_2.get() :
        print('Checkbox 2 selected')
    else :
        print('Checkbox 2 unselected')
 
def check3Clicked():
    if check_3.get() :
        print('Checkbox 3 selected')
    else :
        print('Checkbox 3 unselected')
 
check_but_1 = tkinter.Checkbutton(window_main, text = 'Listening to Music', variable = check_1,
                onvalue = 1, offvalue = 0, command=check1Clicked)
check_but_1.pack()
 
check_but_2 = tkinter.Checkbutton(window_main, text = 'Reading Books', variable = check_2,
                onvalue = 1, offvalue = 0, command=check2Clicked)
check_but_2.pack()
 
check_but_3 = tkinter.Checkbutton(window_main, text = 'Watching Movies', variable = check_3,
                onvalue = 1, offvalue = 0, command=check3Clicked)
check_but_3.pack()
 
window_main.mainloop()
Posted by: Guest on September-06-2021

Browse Popular Code Answers by Language