英文:
customtkinter - is there a way to perform validation on ComboBoxes?
问题
你可以在输入框小部件上使用 "validate" 和 "validatecommand",但无法在组合框上执行它们。有没有任何方法可以这样做?
self.ESubject = ctk.CTkComboBox(
self,
values=["option1", "option2"],
**_entry_options
)
self.ESubject.grid(row=0, column=1, sticky="ew")
self.ESubject.configure(validate="key", validatecommand=(string_reg, '%P'))
使用这个会引发错误,指出 "validate" 和 "validatecommand" 是不支持的参数。我可以做什么?
英文:
You can use validate and validatecommand on Entry widgets but you can't perform them on comboboxes.
Is there anyway to do so?
self.ESubject = ctk.CTkComboBox(
self,
values = ["option1", "option2"],
**_entry_options
)
self.ESubject.grid(row = 0, column = 1, sticky = "ew")
self.ESubject.configure(validate = "key", validatecommand = (string_reg, '%P'))
Using this raises an error that states that 'validate' and 'validatecommand' are unsupported args. What can I do?
答案1
得分: 1
你可以配置内部输入小部件如下:
self.ESubject._entry.configure(validate="key", validatecommand=(string_reg, '%P'))
英文:
You can configure the internal entry widget instead:
self.ESubject._entry.configure(validate="key", validatecommand=(string_reg, '%P'))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论