装有黑匣子时,将显示tkk复选按钮 [英] tkk checkbutton appears when loaded up with black box in it

查看:109
本文介绍了装有黑匣子时,将显示tkk复选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的调用创建一个复选框/框

  x = ttk.Checkbutton(tab1,state ='已禁用',命令= lambda j = i,x = k:fCheckButton(j,x))
x.state(['selected'])

该框看起来很好并且被选中,但是它在加载时出现,其中有一个黑框,这似乎与它的状态无关。 / p>

我一直在寻找原因,但实际上找不到任何遇到相同问题的人。



谢谢

解决方案

我在Windows 7上也遇到过类似的问题。



加载该应用程序后,我的一个复选按钮包含一个实心方块。但是点击它之后,它变成了一个普通的检查按钮:





在我的情况下,这是因为我有多个共享相同变量的检查按钮...为每个检查按钮创建了单独的 Tk.IntVar()变量后,问题消失了。

 进口Tkinter为Tk 
进口ttk

根= Tk.Tk ()

checkVar = Tk.IntVar()
x = ttk.Checkbutton(root,variable = checkVar,text = check 1)
x.pack()

checkVar2 = Tk.IntVar()
y = ttk.Checkbutton(root,variable = checkVar2,text = check 2)
y.pack()

root.mainloop()


I create a check button / box, with the following call

x=ttk.Checkbutton(tab1,state='disabled',command = lambda j=i,x=k: fCheckButton(j,x))
x.state(['selected'])

The box appears fine and is selected, but it appears on load up, with a black box in it, which seems to have nothing to do with the state of it.

I have looked for reasons why, but can't actually find anyone with the same problem.

thanks

解决方案

I've had a similar issue on Windows 7.

After loading the app, one of my checkbuttons contained a filled square. But after clicking on it, it became a normal checkbutton:

In my case, it was because I had multiple checkbuttons sharing the same variable... After creating a separate Tk.IntVar() variable for each checkbutton, the problem disappeared.

import Tkinter as Tk
import ttk

root = Tk.Tk()

checkVar = Tk.IntVar()
x = ttk.Checkbutton(root, variable=checkVar, text="check 1")
x.pack()

checkVar2 = Tk.IntVar()
y = ttk.Checkbutton(root, variable=checkVar2, text="check 2")
y.pack()

root.mainloop()

这篇关于装有黑匣子时,将显示tkk复选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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