0

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.

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
newbie
  • 1
  • What exactly are you trying to have it display? All you have is it getting IntVar() which is 0 currently because you didnt define it as something else – SpacedOutKID Aug 15 '20 at 14:02

1 Answers1

2

You should not create more than one root window, see Why are multiple instances of Tk discouraged?

Instead use Toplevel() to create the dialog:

def show_hide_option_func():
    master = Toplevel()
    etc...
figbeam
  • 7,001
  • 2
  • 12
  • 18