如何在 tkinter 中禁用 Treeview 的多选

How to disable multiselection on Treeview in tkinter

我有一个 Treeview 小部件,一次只需要选择一个 row/item。我一直在阅读 the doc,但我找不到任何 属性 或方法,也没有在 SO 上找到有用的东西。

可能吗?怎么做?

答案是a bit higher up the page:

selectmode

Controls how the built-in class bindings manage the selection. One of “extended”, “browse” or “none”. If set to “extended” (the default), multiple items may be selected. If “browse”, only a single item will be selected at a time. If “none”, the selection will not be changed.

Note that the application code and tag bindings can set the selection however they wish, regardless of the value of this option.

设置 selectmode="browse" 应该会提供您所要求的行为。