ttk Treeview selection_set不能接受空格

Dav*_*ili 4 python treeview ttk

我正在使用python中的tkk构建一个gui,我遇到了Treeview命令问题selection_set().我正在尝试使用它来设置我的程序启动时的默认选择,但似乎它不能接受带有空格的字符串.

tree.selection_set("Sunset Grill")
Run Code Online (Sandbox Code Playgroud)

原因:

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

谁能提出任何建议?

Joh*_*Jr. 6

您可以尝试以下方法:

tree.selection_set('"Sunset Grill"')
Run Code Online (Sandbox Code Playgroud)

我猜这是基于ttk.py的代码和我对Tcl的有限理解.对tree.selection_set()的调用调用self.selection("set",items),而后者调用self.tk.call(self._w, "selection", selop, items)selop ='set',而items是最初传递给selection_set()的字符串.我不确定self.tk.call()是否正在对参数进行任何按摩,然后将它们传递给Tcl,因为它是对_tkinter.c模块的调用,而我对Python/C接口的了解还不够grok那个代码.;)