选中后如何获取Checkbutton的状态? [英] How to get state of Checkbutton when it's selected?

查看:733
本文介绍了选中后如何获取Checkbutton的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I get the state of a Checkbutton in python? I have this:

def doSomething():

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

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


推荐答案

您需要关联带有变量的复选框

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

然后利用做您的检查,例如:

Then utilise do your check such as:

if is_checked.get():
    # do something

这篇关于选中后如何获取Checkbutton的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆