Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse wheel crashes program #39484

Closed
garyrxx mannequin opened this issue Nov 2, 2003 · 12 comments
Closed

Mouse wheel crashes program #39484

garyrxx mannequin opened this issue Nov 2, 2003 · 12 comments
Assignees
Labels
topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@garyrxx
Copy link
Mannequin

garyrxx mannequin commented Nov 2, 2003

BPO 834351
Nosy @loewis, @birkenfeld, @terryjreedy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/loewis'
closed_at = <Date 2009-08-03.17:14:02.120>
created_at = <Date 2003-11-02.00:37:18.000>
labels = ['type-bug', 'expert-tkinter']
title = 'Mouse wheel crashes program'
updated_at = <Date 2009-08-03.17:14:02.118>
user = 'https://bugs.python.org/garyrxx'

bugs.python.org fields:

activity = <Date 2009-08-03.17:14:02.118>
actor = 'gpolo'
assignee = 'loewis'
closed = True
closed_date = <Date 2009-08-03.17:14:02.120>
closer = 'gpolo'
components = ['Tkinter']
creation = <Date 2003-11-02.00:37:18.000>
creator = 'garyrxx'
dependencies = []
files = []
hgrepos = []
issue_num = 834351
keywords = []
message_count = 12.0
messages = ['18848', '18849', '18850', '18851', '18852', '18853', '18854', '18855', '18856', '18857', '84141', '91233']
nosy_count = 10.0
nosy_names = ['loewis', 'georg.brandl', 'terry.reedy', 'corvus', 'garyrxx', 'ash101', 'johnfouhy', 'sdati', 'orthorim', 'gpolo']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'test needed'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue834351'
versions = ['Python 2.6']

@garyrxx
Copy link
Mannequin Author

garyrxx mannequin commented Nov 2, 2003

The following program (by Michael Peuser) crashes as
soon as the mouse wheel is moved. See my post to
c.l.p. on Oct 29.

Gary Richardson

#-------------------------

from Tkinter import *
def _onMouseWheel(event):
    print event

root = Tk()
root.bind('<MouseWheel>',_onMouseWheel)
root.mainloop()

@garyrxx garyrxx mannequin assigned loewis Nov 2, 2003
@garyrxx garyrxx mannequin added the topic-tkinter label Nov 2, 2003
@garyrxx garyrxx mannequin assigned loewis Nov 2, 2003
@garyrxx garyrxx mannequin added the topic-tkinter label Nov 2, 2003
@loewis
Copy link
Mannequin

loewis mannequin commented Nov 2, 2003

Logged In: YES
user_id=21627

What operating system are you using?

@garyrxx
Copy link
Mannequin Author

garyrxx mannequin commented Nov 3, 2003

Logged In: YES
user_id=899035

I'm using Win98SE.

@ash101
Copy link
Mannequin

ash101 mannequin commented Dec 4, 2003

Logged In: YES
user_id=923903

Happens for me too, on Win2K with python 2.3.2. The fault is
in TCL84.DLL at an offset of 1002a58c, if that means
anything to anyone.

@johnfouhy
Copy link
Mannequin

johnfouhy mannequin commented Oct 26, 2004

Logged In: YES
user_id=1084032

I can reproduce this bug. I am running Python 2.3.4 on
WinXP SP2.

tk84.dll is version 8.4.3; tcl84.dll is also 8.4.3.

The mousewheel works correctly with a Tkinter.Text object
with no additional bindings.

@corvus
Copy link
Mannequin

corvus mannequin commented Jan 4, 2005

Logged In: YES
user_id=2138

Me too. Python 2.3.4 with Tcl/Tk 8.4.9. Crash on Scroll Wheeling in WinXP
SP 1. (users report it happening in SP 2 also).

I'll try to make this happen in pure Tcl/Tk rather than Tkinter too.

@corvus
Copy link
Mannequin

corvus mannequin commented Jan 4, 2005

Logged In: YES
user_id=2138

I wasn't able to reproduce this in pure Tcl/Tk (under Wish). No surprise
there. In wish, I used this:

toplevel .top
bind .top <MouseWheel> {puts 'foo'}

And mouse wheeling in the Toplevel widget made a bunch of 'foo's appear in
the wish console without crashing.

HTH.

@sdati
Copy link
Mannequin

sdati mannequin commented Feb 8, 2005

Logged In: YES
user_id=1214285

I have determined the root cause of this problem. It actually does lie in
Tk, but is only revealed by Python Tkinter because of the way Python
deals with events.

From Tk source -- tkWinX.c:

case WM_MOUSEWHEEL:
...
event.xany.send_event = -1
...

This line causes Tk to call TkpGetString() when ExpandPercents() is
called with '%A' (which is done by Python for ALL events, including
<MouseWheel>). This, in turn, causes segmentation fault because
event.xkey.trans_chars and event.xkey.nbytes are not initialized.

So, the workaround from the Python side is pretty ugly, but I have
tested it and verified that it works. There is probably a better way, but
this was the obvious solution to me, since I have never needed to look at
the Tkinter interface before:

In Tkinter.py, define a new _subst_format and _subst_format_str:

    _subst_format_workaround = ('%#', '%b', '%f', '%h', '%k',
             '%s', '%t', '%w', '%x', '%y',
             '%D', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
    _subst_format_str_workaround = " ".join(_subst_format_workaround)

Note that '%A' entry in _subst_format is replaced with '%D' entry in
_subst_format_workaround.

Now, in Misc._bind(),

if sequence == "<MouseWheel>":
    cmd = ('%sif {"[%s %s]" == "break"} break\n'
           %
           (add and '+' or '',
            funcid, self._subst_format_str_workaround))
else:
    cmd = ('%sif {"[%s %s]" == "break"} break\n'
           %
           (add and '+' or '',
            funcid, self._subst_format_str))

I am submitting this bug to Tcl/Tk maintainers to request that they fix
(Project: Tk Toolkit Request ID 1118340), but in the meantime (and for
all older versions of Tk), it seems like a workaround in the Tkinter code
might be appropriate.

@orthorim
Copy link
Mannequin

orthorim mannequin commented May 12, 2005

Logged In: YES
user_id=933256

sdati, thanks for this workaround. it's awesome. i am now
happily mouse-wheeling :)

I did make a small improvement to it so it works for all
MouseWheel type events. Instead of
if sequence == "<MouseWheel>":
i say
if type(sequence) == str and
sequence.__contains__("MouseWheel"):

This way, all permutations of mouse events are covered, e.g.
"<Control-MouseWheel>"

@birkenfeld
Copy link
Member

Logged In: YES
user_id=1188172

Bumping, as it is still the same with 2.4 on my box.

@devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error labels Feb 13, 2009
@terryjreedy
Copy link
Member

3.0.1, WinXP, with two 3.0 revisions:

from tkinter import *
def _onMouseWheel(event):
    print(event)

root = Tk()
root.bind('<MouseWheel>',_onMouseWheel)

In IDLE shell, nothing changes, wheel works normally.

In interpreter window, wheel continues to work normally.
After click on tk window, wheel generates
<tkinter.Event object at 0x00ACE970>
messages in interpreter window.

Unless someone can verify that there is a problem in 2.6.1, or in 3.0.1
on other hardware, we should close this.

@gpolo
Copy link
Mannequin

gpolo mannequin commented Aug 3, 2009

This is a tk issue, so the best way to fix this (if you don't want to
install something newer than Python 2.4 on Windows) is to install a
newer tcl/tk version.

Unfortunately the proposed workaround is way too specific, imagine if
other bindings had similar problems with different binding substitutions.

If we want to be safe, Tkinter should be passing only valid
substitutions for a given sequence but this is very awkward. But check
what the bind manual says ".. Some of the substitutions are only valid
for certain types of events; if they are used for other types of events
the value substituted is undefined.", note how it doesn't say ".. if
they are used for other types of events a segfault ensues".

@gpolo gpolo mannequin closed this as completed Aug 3, 2009
@gpolo gpolo mannequin closed this as completed Aug 3, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants