我有一个组合框,我现在可以在其中输入内容。我希望这样用户只能从下拉列表中选择一个有效选项。
我似乎无法在网上找到类似的问题,而且我在文档中也没有看到任何可以帮助我的问题。
最佳答案
您可以将state
设置为"readonly"
cb = ttk.Combobox(root, state="readonly",
values=("one", "two", "three"))
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/