2

I have attached a function (comhelms) to my check button. It works normally by calling the function when I check the box. However, unchecking the box calls the function as well. How can I avoid this?

  i = Checkbutton(helmsframe, variable = helmscblist[i], command = comhelms)
0

1 Answer 1

3

You can't prevent the callback from being called when unchecking your checkbutton. But inside the callback function, you can easily use the associated variable to know whether the box was just checked or unchecked:

var = tk.IntVar()

def cb():
    if var.get():
        print("box checked")
    else:
        print("box unchecked")

c = tk.Checkbutton(parent, variable=var, command=cb)
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.