Skip to content

keypad number presses not properly registered by tk #9493

@anntzer

Description

@anntzer

Bug report

Bug summary

Pressing keypad numbers do not report keys correctly under tkagg+linux, if numlock is active (i.e. when numbers should be reported); numbers are incorrectly reported when numlock is inactive (i.e. when numbers should not be reported).

Code for reproduction

MPLBACKEND=tkagg python -c 'from pylab import *; gcf().canvas.mpl_connect("key_press_event", lambda event: print(event.key)); show()'

Actual outcome

numbers are printed when numlock is inactive, and vice versa.

Expected outcome

the opposite

Matplotlib version

  • Operating system: ubuntu
  • Matplotlib version: 2.0.2 (but likely irrelevant
  • Matplotlib backend (print(matplotlib.get_backend())): tkagg
  • Python version: 3.6
  • Jupyter version (if applicable):
  • Other libraries:

This is due to FigureCanvasTkAgg.keyvald using incorrect values for the mapping: it uses the values at http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html (KP_0, etc.) but the correct values (in the tk sources themselves...) are at https://github.com/tcltk/tk/blame/a1577313301d5ad9a6e553b359f7e5de2b8f6153/generic/ks_names.h (themselves derived from https://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h) and suggests that the numlock state got inverted.

On Windows this is irrelevant, keypad presses are reported with a keyval_sym <256 and thus directly converted via ASCII to the correct value. Not sure about the situation under OSX.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions