python - ttk Treeview selection_set 不能接受空格

标签 python treeview ttk

我正在 python 中使用 tkk 构建一个 gui,但我在使用 Treeview 命令 selection_set() 时遇到了问题。我试图在我的程序启动时使用它来设置默认选择,但它似乎无法接受其中包含空格的字符串。

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().

我不确定 self.tk.call() 在将参数传递给 Tcl 之前是否对参数进行了任何处理,因为它是对 _tkinter.c 模块的调用 而且我对 Python/C 接口(interface)的了解还不够,无法理解该代码。 ;)

关于python - ttk Treeview selection_set 不能接受空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10691257/

相关文章:

python - 将数据表示为傅里叶变换或高次多项式?

python - Pandas - groupby "longest"带薪休假 (PTO) 持续时间

c# - MVVM 与 TreeView - 添加节点

python-3.x - 在 Python 3 中使用 tkinter 更改单选按钮的背景颜色

Python:带有域检查的线性代数包

python - 试图打开一个文本文件并创建一个分隔句子的行列表。

wpf - 在右键单击MVVM的treeView中选择节点

c# - 在 TreeView c# 中向上移动树节点的处理程序崩溃

python - 任何 ttk TreeView 行的不同 tkinter 绑定(bind)

python - ttk.Button 返回 None