| Ticket UUID: | 3565268 | |||
| Title: | bind<ButtonRelease-1> doesnt have same behavior on windows | |||
| Type: | Bug | Version: | 8.6.18, 9.0.5, 9.1.0 | |
| Submitter: | dgp | Created on: | 2012-09-06 11:58:51 | |
| Subsystem: | 01. Bindings | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Pending | Last Modified: | 2026-11-19 12:40:37 | |
| Resolution: | Fixed | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
Copied over from
http://sf.net/tracker/?func=detail&aid=3565164&group_id=10894&atid=110894
see that ticket for the attachment.
I write a xml layout feature for my work, recently. And I want bind a radiobutton or checkbutton click event on a method, but do not affect "command" configure option.
so I use the Events and Bindings, I write it like this widget.bind("<ButtonRelease-1>", lambda event: self.enable_toggle(data))
and
def enable_toggle(self, widget):
print widget_value_map[widget].get() # this will get the widget's variable and get it value.
on linux platform, the <ButtonRelease-1> event will be called after variable change, so I get the correct value in enable_toggle
but on windows platform, the event will be called before variable change, so I get the wrong value.
version:(python version 2.7.3)
Linux:
>>> Tkinter.TkVersion
8.5
>>> Tkinter.TclVersion
8.5
Windows:
>>> Tkinter.TkVersion
8.5
>>> Tkinter.TclVersion
8.5
I wrte a simple code(attachment) to show this bug. I want the code have same result on linux and windows, but it doesnt.
BTW: Is there a way to bind multiple method to an button click event? If a better one please tell me. Thank you. mailto: [email protected]
| |||
| User Comments: |
jan.nijtmans added on 2026-11-19 12:40:37:
Merged to [517d6eefa666b8c9|trunk]. As soon as the CI build succeeds, it can be backported to 9.0 and 8.6 as well. serhiy.storchaka added on 2026-10-08 12:08:34: On X11, the classic checkbutton and radiobutton were invoked when mouse button 1 was pressed. On Windows and macOS they are invoked when it is released, in the class binding, which runs after the widget binding. All other toolkits on X11 also toggle on release: Motif, Athena, GTK 3, GTK 4 and Qt 6. So do Tk's ttk checkbutton and radiobutton on all platforms. Proposed fix in branch [57bfd88713|x11-check-toggle-on-release]: on X11 the classic checkbutton and radiobutton are now invoked on release, and not invoked if the mouse is not over the button when it is released. The man pages are updated, and new tests button-17.1–17.3 are added. A widget <ButtonRelease-1> binding still sees the old value, now on all platforms. To act after the value changes, use the -command option, a trace on the variable, or bind to a tag placed after the class in bindtags. dkf added on 2012-09-12 03:17:46: I don't know for sure (not being a Win developer) but I think the problem relates to how Win native buttons handle events. Which is a bummer, because that's very hard to fix. More detail: I think it's probably linked to just when the button decides to fire. Classic Unix buttons (and radiobuttons and checkbuttons) do it when the <ButtonRelease-1> event hits an armed button, and they process the event in their class binding (i.e., after the widget-specific bindings). But this bug report provides evidence that Win native *buttons work differently. I didn't even know that they did that, but if it is true then it's hard to change. It's even possible that the platform guidelines call for checkbuttons/radiobuttons to change on <ButtonPress-1> events; if that's the case (don't know if it is) your plan won't work at all. In short, I'm not at all sure what we could (or should) do about it. Saving the value on <ButtonPress-1> might be easier (you can just store it in case a subsequent <ButtonRelease-1> happens over the widget). Mind you, coding with GUI events remains tricky because they're fairly asynchronous and can be mixed up in order a lot. And I guess I'm not being very helpful. :-( | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki