简体   繁体   English

ttk Treeview selection_set 不能接受空格

[英]ttk Treeview selection_set can't accept spaces

I'm building a gui using tkk in python and I'm having trouble with the Treeview command selection_set() .我正在使用 python 中的 tkk 构建一个 gui,我在使用Treeview命令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?任何人都可以提供任何建议吗?

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.我猜测这是基于ttk.py的代码和我对 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() .tree.selection_set()调用调用self.selection("set", items) ,后者又调用self.tk.call(self._w, "selection", selop, items)其中selop'set'和 items是最初传递给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.我不确定self.tk.call()在将参数传递给 Tcl 之前是否对参数进行了任何按摩,因为它是对_tkinter.c module的调用,而且我对 Python/C 接口_tkinter.c module理解那个代码。 ;)

尝试tree.selection_set(["Sunset Grill"])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM