gpt4 book ai didi

python - 如何在选中时获取 Checkbutton 的状态?

转载 作者:太空狗 更新时间:2023-10-30 02:21:21 24 4
gpt4 key购买 nike

如何在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com