【问题标题】:Value gets vanished when i check a checkbox in Tkinter当我在 Tkinter 中选中一个复选框时,值会消失
【发布时间】:2017-12-13 10:14:04
【问题描述】:

当我在 Tkinter 中选中一个复选框时,复选框的值消失了。

此问题仅出现在 Linux 中。

我在 Windows 中使用的相同代码,它运行良好。

我参考了这个链接来制作这个 gui

How to create a tree view with checkboxes in Python

代码:

import Tkinter as tk

import Tix as tix

def  selectItem(item):
        
    if cl.getstatus(item) == 'on':
        print("Checked")
    if cl.getstatus(item) == 'off':
        print("Unchecked")

root = tix.Tk()
cl = tix.CheckList(root,browsecmd=selectItem)
cl.pack()
cl.hlist.add("CL1", text="Test")
cl.setstatus("CL1","off")
cl.hlist.add("CL1.Item1", text="child")
cl.setstatus("CL1.Item1","off")
root.mainloop()

检查前:

检查后:

正如您在图像中看到的那样,复选框 Test 在单击测试后消失。此问题仅在 Linux 中发生。谁能给我任何解决方案?

【问题讨论】:

    标签: python checkbox tkinter tix


    【解决方案1】:

    我得到了解决方案。实际上背景和前景的颜色是相同的。所以我改变了前景和背景的颜色。

    import Tkinter as tk
    
    import Tix as tix
    
    def  selectItem(item):
    
        if cl.getstatus(item) == 'on':
            print("Checked")
        if cl.getstatus(item) == 'off':
            print("Unchecked")
    
    root = tix.Tk()
    cl = tix.CheckList(root,browsecmd=selectItem)
    cl.hlist.config(bg='White',bd=0,selectmode='none',selectbackground='white',selectforeground='black',drawbranch=True)
    cl.pack()
    cl.hlist.add("CL1", text="Test")
    cl.setstatus("CL1","off")
    cl.hlist.add("CL1.Item1", text="child")
    cl.setstatus("CL1.Item1","off")
    root.mainloop()  
    

    【讨论】:

      猜你喜欢
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      • 2020-05-23
      • 2015-06-19
      • 2018-04-15
      • 2021-12-23
      相关资源
      最近更新 更多