classification
Title: Behaviour of disabled widgets: widget.bind(func) -vs- w = widget(command=func)
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: gpolo, mrshr3d, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2020-02-16 03:11 by mrshr3d, last changed 2020-02-24 00:37 by terry.reedy. This issue is now closed.

Messages (2)
msg362043 - (view) Author: Clinton Hunter (mrshr3d) Date: 2020-02-16 03:11
Using the bind method, the event will still trigger when the widget is disabled.  However, if using "command=" it doesn't.  Wondering whether the behaviour between the two ways of setting up event handling should behave the same?  Not a major issue, easy enough to work around using an if.

Example:

Clicking the printBtn will still work despite being disabled.

self.printBtn = tkinter.Button(self.frame, text='Print')
self.printBtn['state'] = tkinter.DISABLED
self.printBtn.bind(sequence='<Button-1>', func=self.printBtn_onclick)
self.printBtn.pack()


Clicking on the save button, the event will not trigger (ie the disabled state attribute is honored)

self.saveBtn = tkinter.Button(self.frame, text='Save', command=self.saveBtn_onclick)
self.saveBtn['state'] = tkinter.DISABLED
self.saveBtn.pack()
msg362553 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-02-24 00:37
I am sure that the behavior you observe is correct.  The default button click handler must check the state before calling the command function, while I presume that your printBtn_onclick function (not shown) does not.  If Serhiy disagrees, he can reopen.
History
Date User Action Args
2020-02-24 00:37:41terry.reedysetstatus: open -> closed

nosy: + terry.reedy
messages: + msg362553

resolution: not a bug
stage: resolved
2020-02-16 07:06:48SilentGhostsetnosy: + gpolo, serhiy.storchaka
2020-02-16 03:11:33mrshr3dcreate