简体   繁体   English

False 时使 tkinter ttk 复选框为空

[英]Make tkinter ttk checkbutton be empty when False

I was making a simple interface with Tkinter, and noticed that when their Checkbutton value is False, or not clicked, it displays a black square covering the button, instead of simply being empty.我正在使用 Tkinter 制作一个简单的界面,并注意到当它们的Checkbutton值为 False 或未单击时,它会显示一个覆盖按钮的黑色方块,而不是简单地为空。 Example:例子: 例子 . . All I wanted is to make the button completely empty when it's state is False, did a bit of digging and couldn't find it.我只想让按钮在 state 为 False 时完全为空,进行了一些挖掘却找不到它。 Thanks for your time and help!感谢您的时间和帮助!

Here's the code in question:这是有问题的代码:

querlog = ttk.Checkbutton(window, text='Quero salvar o log', command=quer_salvar_log)
querarquivo = ttk.Checkbutton(window, text='Quero salvar o arquivo de som', command=quer_salvar_som)

You should associate a variable with the checkbutton, and you need to make sure the variable is set to the same value as the offvalue option.您应该将变量与检查按钮相关联,并且需要确保将变量设置为与offvalue选项相同的值。 The offvalue defaults to zero. offvalue默认为零。 You also need to make sure to retain a reference so that the variables don't get destroyed by the garbage collector (ie: don't use local variables)您还需要确保保留引用,以便变量不会被垃圾收集器破坏(即:不要使用局部变量)

querlog_var = tk.StringVar(value=0)
querarquivo_var = tk.StringVar(value=0)

querlog = ttk.Checkbutton(window, text='Quero salvar o log', command=quer_salvar_log, variable=querlog_var)
querarquivo = ttk.Checkbutton(window, text='Quero salvar o arquivo de som', command=quer_salvar_som, variable=querarquivo_var)

I noticed the same issue when not using variable= so here is how to do it:我在不使用variable=时注意到了同样的问题,所以这里是如何做到的:

Checkbutton(master, variable='', **kwargs)

You can just set variable attribute as an empty string and that should fix it您可以将variable属性设置为空字符串,这应该可以解决它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM