Tkinter Checkbutton 卡住 Unchecked [英] Tkinter Checkbutton stuck Unchecked

查看:22
本文介绍了Tkinter Checkbutton 卡住 Unchecked的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 tkinter 的小应用程序.我让一切正常,然后做了一些改变,我不知道我做了什么.在我的 gui 中有一个复选框.如果我在没有任何反应后单击复选框.如果我第二次单击它,复选标记会闪烁然后消失.我的代码大部分都遵循这种格式.

I have a small app that uses tkinter. I had everything working perfectly then made some changes and I have no idea what I did. In my gui there is one check box. If I click the checkbox once nothing happens. If I click it a second time the check mark flashes then disappears. My code follows this format for the most part.

在 Windows 10 上使用 Python 3.6

Using Python 3.6 on Windows 10

def foo():
    x = chk.get()
    if x:
        print('hello')

root = Tk()
chk = IntVar()

c = Checkbutton(root, text='Check for CSV Instead', variable=chk, bg='#45484c', fg='white')
c.grid(row=3, column=3)
root.mainloop

我没有对复选按钮或与之相关的任何变量进行任何直接更改.没有错误.闪烁让我怀疑该变量不知何故被覆盖,但就像我之前所说的那样.

I did not make any direct changes to the checkbutton or any variable connected to it. There are no errors. The flashing makes me suspect that the variable is somehow being overwritten but like I said it was working before.

在我的研究中,我遇到了这个我觉得是我发生了什么事,但我检查了代码,我不相信我正在这样做.

In my research I came across this Which I feel is what is happening to me but I have checked the code and I do not believe I am doing that.

推荐答案

白色是有罪的,它使检查符号不可见

The color white is guilty, it makes the check sign invisible it's more reproducible with

c = Checkbutton(root, text='Check for CSV Instead', variable=chk, bg='#45484c', fg='#e5e5e5')

这篇关于Tkinter Checkbutton 卡住 Unchecked的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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