0

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()
Community
  • 1
  • 1
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68
  • I apologize for the absence of the image. This is the first time I am trying to attach an image and I am not being successful. I have attached the file treeview.png by using the provided interface and it inserted something like ![description][1], which did not do the job. I tried ![description](treeview.png), which is still not successful. I will very much appreciate help with this. – AlwaysLearning Feb 12 '15 at 17:37
  • I don't see a question anywhere. – Bryan Oakley Feb 12 '15 at 18:22
  • The question is: what is the reason for the glitch and how do I get rid of it? – AlwaysLearning Feb 12 '15 at 18:32
  • 1
    Questions of the form "why does my code not work" are off topic here on stackoverflow. Your question will likely be closed unless you can ask a more specific question. – Bryan Oakley Feb 12 '15 at 18:40
  • Bryan, thank you for the suggestion. I have modified the question. Please let me know if you still believe that the question is not asked in a suitable manner. Otherwise, please vote it up. – AlwaysLearning Feb 12 '15 at 19:05

1 Answers1

0

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")
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68