def add_combobox(self, key, choices, text, *, case_sensitive=True):
"""Add a ``ttk.Combobox`` that sets an option to a string.
The combobox will contain each string in *choices*.
A `validator callback <Validating>`_ that ensures the value is
in *choices* is also added. If *case_sensitive* is False,
:meth:`str.casefold` is used when comparing the strings.
"""
def validator(value):
if case_sensitive:
ok = (value in choices)
else:
ok = (value.casefold() in map(str.casefold, choices))
if not ok:
raise InvalidValue("%r is not a valid %r value"
% (value, key))
self.connect(key, validator)
frame = self.add_frame(key)
ttk.Label(frame, text=text).pack(side='left')
ttk.Combobox(frame, values=choices,
textvariable=self.get_var(key)).pack(side='right')
评论列表
文章目录