ttk Treeview selection_set 不能接受空格 [英] ttk Treeview selection_set can't accept spaces
问题描述
我正在使用 python 中的 tkk 构建 gui,但在使用 Treeview
命令 selection_set()
时遇到了问题.我正在尝试使用它来设置程序启动时的默认选择,但它似乎无法接受其中包含空格的字符串.
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")
原因:
return self.tk.call(self._w, "selection", selop, items)
_tkinter.TclError: Item Sunset not found
谁能给点建议?
推荐答案
您可以尝试以下操作:
tree.selection_set('"Sunset Grill"')
我猜测这是基于 ttk.py
的代码和我对 Tcl 的有限理解.对 tree.selection_set()
的调用调用了 self.selection("set", items)
,后者又调用了 self.tk.call(self._w, "selection", selop, items)
其中 selop
是 'set'
并且 items 是最初传递给 selection_set()代码>.
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
is 'set'
and items is the string initially passed to selection_set()
.
我不确定 self.tk.call()
在将参数传递给 Tcl 之前是否对参数进行了任何处理,因为它是对 _tkinter.c 模块的调用
并且我对 Python/C 接口的了解还不够深入了解该代码.;)
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. ;)
这篇关于ttk Treeview selection_set 不能接受空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!