1

I need to implement tree view with checkbox.

Below is my code:

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()

There is a problem; If a checkbox is checked, the value of checkbox gets printed twice for single check.

Can anyone please help me to solve the issue such that the value is printed once?

SiHa
  • 7,830
  • 13
  • 34
  • 43

1 Answers1

0

I think because clicking the mouse is classified as one event and then releasing the mouse as another. If you keep it pressed, you see the value printed only once. Release it and the print statement is called again.

Arvind
  • 1