如何在python中获取Checkbutton的状态?我有这个:

def doSomething():

  if #code goes here, if checkbutton is selected
   ...

check = Checkbutton(window, text="Add both", onvalue = 1, offvalue = 0)
check.pack(side="right")

最佳答案

您需要将 Checkbox 与一个变量相关联:

is_checked = IntVar()
check = Checkbutton(window, text="Add both", onvalue=1, offvalue=0, variable=is_checked)

然后利用做你的检查,如:
if is_checked.get():
    # do something

关于python - 选中 Checkbutton 时如何获取它的状态?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16778424/

10-10 03:18