[Python] tkinter Combobox disable typing

default combo 是可以輸入的,問題會不是預期的文字內容,而且也無法使用 bind(‘<>’) 去處理使用者輸入的內容。解法:

You can set the state to "readonly"

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

From the 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.

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *