samedi 15 août 2020

Tkinter Checkbutton doesn't change variable

What problem with checkbox tkinter python. whatever I ticked on checkbox or not, I always got 0 from variable. I also try set value for variable but the checkbutton did not change! What wrong did i had.

from tkinter import *
master_1 = Tk()


def show_hide_option_func():
    master = Tk()
    Label(master, text="Your sex:").grid(row=0, sticky=W)
    check_list = IntVar()
    check_song = IntVar()
    check_vol = IntVar()

    def var_state():
        print(check_list.get())
        print(check_song.get())
        print(check_vol.get())

    b= Checkbutton(master, text="female", variable=check_list).grid(row=2, sticky=W)
    c= Checkbutton(master, text="male", variable=check_song).grid(row=3, sticky=W)
    d= Checkbutton(master, text="feme", variable=check_vol).grid(row=4, sticky=W)

    Button(master, text='Quit', command=master.quit).grid(row=5, sticky=W, pady=4)
    Button(master, text='Show', command=var_state).grid(row=6, sticky=W, pady=4)
    master.mainloop()

Button(master_1,command=show_hide_option_func, text='Click here').pack()
master_1.mainloop()

enter image description here Thank you.




Aucun commentaire:

Enregistrer un commentaire