Class and tkinter problem
Paulo da Silva
p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt
Thu Jan 7 12:28:20 EST 2021
Às 09:20 de 07/01/21, Terry Reedy escreveu:
> On 1/7/2021 2:42 AM, Christian Gollwitzer wrote:
>> Am 07.01.21 um 08:29 schrieb Paulo da Silva:
>>
>>> Does anybody know why cmd method isn't called when I change the button
>>> state (clicking on it) in this example?
>>> I know that this seems a weird class use. But why doesn't it work?
>>> Thanks.
>>>
>>> class C:
>>> from tkinter import Checkbutton
>>> import tkinter
>>>
>>> @staticmethod
>> ^^it works if you remove the staticmethod here
>
> staticmethods are essentially useless in Python. What little was gained
> by their addition is partly offset by the introduced confusion.
It depends on what the classes are being used for.
Sometimes I just want to use them as static wrappers.
Of course I could use them in the conventional way for this purpose, but
it's not so clean :-)
...
>
> Classmethods also do not work as is. By experiment, the following works.
> cb=Checkbutton(command=lambda: C.cmd.__func__(C))
Why not just
cb=Checkbutton(command=lambda : C.cmd()) ?
Also works.
BTW, just for curiosity, and for my personal learning ... What does
"__func__" does?
Thank you.
More information about the Python-list
mailing list