For my first GUI in Python, I'm using Tix for its built-in 'checklist' and 'hlist' widgets to construct a tree view with checkboxes against each branch and leaf of the tree. It is mostly working well. But the one thing that I have not been able to figure out is how to programmatically collapse branches of the tree.
I would like to have some branches collapsed when the checklist is first displayed and to be able to have a button to "Collapse All" and a button to "Expand All".
Below is the checklist portion of my code. I was hoping that the checkList.close(i["id"])
line might close the branch, but it does not.
Can anybody educate me on the correct way to programmatically collapse a branch in a Tix checklist/hlist tree ?
checkList = Tix.CheckList(win)
checkList.pack(in_=frameTop, side=Tix.LEFT, fill=Tix.BOTH, expand=Tix.YES)
checkList.hlist.config(bg='white', selectbackground='white', selectforeground='black', header=True, browsecmd=itemEvent)
checkList.hlist.header_create(0, itemtype=Tix.TEXT, text='Select layers to add to the map', relief='flat')
checkList.hlist.bind("<ButtonRelease-1>", checkListClicked)
for i in items:
try:
checkList.hlist.add(i["id"], text=i["text"])
except:
print "WARNING: Failed to add item to checklist: {} - {}".format(i["id"], text=i["text"])
checkList.close(i["id"])
checkList.setstatus(i["id"], "off")
checkList.autosetmode()
I would have expected the following to work (eg, within the above for loop):
checkList.setmode(i["id"], "close")
checkList.close(i["id"])
But it gives me the error, AttributeError: setmode
. Which is odd, because as far as I can tell, setmode
should be available, right?