customtkinter – 是否有一种方法可以在组合框上执行验证?

huangapple go评论84阅读模式
英文:

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'))

huangapple
  • 本文由 发表于 2023年5月17日 10:54:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268280.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定