python - 如何禁止在 ttk.Combobox tkinter 中输入内容?

标签 python tkinter

我有一个组合框,我现在可以在其中输入内容。我希望这样用户只能从下拉列表中选择一个有效选项。

我似乎无法在网上找到类似的问题,而且我在文档中也没有看到任何可以帮助我的问题。

最佳答案

您可以将state设置为"readonly"

cb = ttk.Combobox(root, state="readonly", 
                  values=("one", "two", "three"))

来自python 3.6 documentation :

state: One of “normal”, “readonly”, or “disabled”. In the “readonly” state, the value may not be edited directly, and the user can only selection of the values from the dropdown list. In the “normal” state, the text field is directly editable. In the “disabled” state, no interaction is possible.

关于python - 如何禁止在 ttk.Combobox tkinter 中输入内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44959253/

相关文章:

python - 如何在 tkinter 中插入特殊字符

python - 如何更新 Canvas 上的图像?

python - 调用 python 对象时超出最大递归深度

python - Pandas 内存错误

python - Dask 分布式诊断网页无法正常工作

python - 正则表达式多行 - 如何获取页面源的一部分

python - tkinter 对 child 的点击不会传播给 parent

Java EE updatetool 出现 Python 解码错误

python - 在AWS s3上删除Delta Lake分区的正确方法

python-3.x - 如何调整 Canvas 可滚动小部件的大小?