我终于想出了一个办法让这件事发挥作用。我放弃了
setmode
完全因为它似乎对我的python环境不可用;然后因为我已经
autosetmode
在那里,我可以用
close
命令之后
自动设置模式
已经跑了。
这意味着我必须在循环中运行两次,这感觉有点浪费,但这不是什么大问题,至少我现在可以得到我需要的结果。
以下是我最后的收获。在本例中,我为每个具有父项的项将分支设置为closed(即,顶级项是打开的,其他项都是关闭的)。
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"])
# Delete this next line
#checkList.close(i["id"])
checkList.setstatus(i["id"], "off")
checkList.autosetmode()
# Add these following lines (include whatever condition you like in the 'if')
for i in items:
if checkList.hlist.info_parent(i["id"]):
checkList.close(i["id"])