[issue45160] ttk.OptionMenu radiobuttons change variable value twice

fhdrsdg report at bugs.python.org
Sat Sep 11 04:47:08 EDT 2021


fhdrsdg <n00rbert at gmail.com> added the comment:

Ah yes, you're right that `command=self._callback` doesn't pass the new value like it should.
Your suggestion does, but throws a "TypeError: 'NoneType' object is not callable" when no command is given when creating the OptionMenu. The current `_setit` implementation uses a `if self.__callback:` check for that.

Should we do something like this?

for val in values:
    menu.add_radiobutton(label=val,
        variable=self._variable)
    if self._callback:
        menu.entryconfigure('last', command=lambda val=val: self._callback(val))


I don't have any experience making pull requests. I might look into it at some point but for now it would be great if you could make it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45160>
_______________________________________


More information about the Python-bugs-list mailing list