ttk Treeview selection_set can't accept spaces

与世无争的帅哥 提交于 2019-12-18 08:52:34

问题


I'm building a gui using tkk in python and I'm having trouble with the Treeview command selection_set(). I'm trying to use it to set the default selection when my program starts but it seems that it can't accept a string with spaces in it.

tree.selection_set("Sunset Grill")

Causes:

return self.tk.call(self._w, "selection", selop, items)
_tkinter.TclError: Item Sunset not found

Can anyone give any suggestions?


回答1:


You might try the following:

tree.selection_set('"Sunset Grill"')

I'm guessing this based on the code for ttk.py and my limited understanding of Tcl. The call to tree.selection_set() calls self.selection("set", items), which in turn calls self.tk.call(self._w, "selection", selop, items) where selop='set' and items is the string initially passed to selection_set(). I'm not sure if the self.tk.call() is doing any massaging of the arguments before passing them to Tcl as it's a call into the _tkinter.c module and I don't know enough about the Python/C interface to grok that code. ;)




回答2:


try tree.selection_set(["Sunset Grill"])



来源:https://stackoverflow.com/questions/10691257/ttk-treeview-selection-set-cant-accept-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!