Creating a Treeview with Checkboxes

淺唱寂寞╮ 提交于 2021-01-29 08:04:25

问题


I am trying to build an application based on the following usage example (How to create a tree view with checkboxes in Python).

This example builds a Treeview with checkboxes using the Tix library. However, when I run this example, whenever a Checkbox is checked, the text label of that box disappears.

Could someone help me to avoid the behaviour mentioned just above?

import Tix

class View(object):
    def __init__(self, root):
        self.root = root
        self.makeCheckList()

    def makeCheckList(self):
        self.cl = Tix.CheckList(self.root, browsecmd=self.selectItem)
        self.cl.pack()
        self.cl.hlist.add("CL1", text="checklist1")
        self.cl.hlist.add("CL1.Item1", text="subitem1")
        self.cl.hlist.add("CL2", text="checklist2")
        self.cl.hlist.add("CL2.Item1", text="subitem1")
        self.cl.setstatus("CL2", "on")
        self.cl.setstatus("CL2.Item1", "on")
        self.cl.setstatus("CL1", "off")
        self.cl.setstatus("CL1.Item1", "off")
        self.cl.autosetmode()

    def selectItem(self, item):
        print item, self.cl.getstatus(item)

def main():
    root = Tix.Tk()
    view = View(root)
    root.update()
    root.mainloop()

if __name__ == '__main__':
    main()

回答1:


The problem is that the default foreground color on selection is the same as the background color. The problem is resolved by adding the following line of code after the initialization of self.cl:

self.cl.hlist.config(selectforeground="black")


来源:https://stackoverflow.com/questions/28483980/creating-a-treeview-with-checkboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!