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.

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 Commented Aug 15, 2020 at 14:02

1 Answer 1

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...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.