0

i can get status of checkbox but How to Get value of checkbox in Tix.

from tkinter 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="C:/")
        self.cl.hlist.add("CL1.Item1", text="subitem1")
        self.cl.hlist.add("CL2", text="some folder")
        self.cl.hlist.add("CL2.Item1", text="test")
        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()     

Expected output

if i click on checkbox c:/ then it should print c:/.I want the value of checkbox.

Output

enter image description here

python_fan
  • 113
  • 2
  • 15

1 Answers1

1

It keeps all in hlist

Official documentation for more informations about hlist sends to tcl/tk documentation and then you can find

pathName item_cget entryPath col option

But it doesn't work as I expected

value = self.cl.hlist.item_cget('CL1.Item1', 0, 'text')

# _tkinter.TclError: unknown option "text"

You have to use "-text" instead of "text"

value = self.cl.hlist.item_cget('CL1.Item1', 0, '-text')
furas
  • 134,197
  • 12
  • 106
  • 148
  • How to find parent path ? (pathName info parent entryPath ). This is given in document but i don't find any useful explanation about it. Can you tell me how to find parent path? – python_fan Dec 09 '17 at 08:37
  • doc shows code in tcl/tk language. In your code `pathName` means `self.cl.hist`, `entryPath` means `CLI1` or `CLI1.Item1`, etc. `parent` probably means `self.root` – furas Dec 09 '17 at 08:44
  • self.cl.hlist.info(self.root,'CL1') is it correct ? – python_fan Dec 09 '17 at 08:50
  • I think it is correct. Try it and you will see error or not :) – furas Dec 09 '17 at 08:53
  • It is giving error : TypeError: pack_info() takes 1 positional argument but 3 were given – python_fan Dec 09 '17 at 08:54
  • 1
    i checked documentation and I see `parent` is bold - it means it will be function `info_parent()` in python. ` `parent_id = self.cl.hlist.info_parent('CL1')` – furas Dec 09 '17 at 08:56
  • Thank you very much...i got the answer – python_fan Dec 09 '17 at 09:00
  • 1
    BTW: try `help(self.cl.hlist)` in code and it will display all functions - sometimes with description. – furas Dec 09 '17 at 09:22