Skip to content

[Bug]: Under Windows and matplotlib 3.5.1, "key_press_event" is not handled #22827

Closed
@thomas-haslwanter

Description

@thomas-haslwanter

Bug summary

The "key_press_event" is not handled. It looks as if this event is not connected by the event handler.

  • This mistake appears under Windows (Win10 & Win11), and NOT under Linux.
  • It does NOT appear with Matplotlib 3.4.1, but DOES appear with Matplotlib 3.5.1

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt


def on_key(event):
    print('you pressed', event.key, event.xdata, event.ydata)


if __name__ == '__main__':
    t = np.arange(0, 20, 0.1)
    x = np.sin(t)

    fig, ax = plt.subplots()

    ax.plot(t, x)
    ax.set_title('Enter a key:')
    fig.canvas.mpl_connect('key_press_event', on_key)
    plt.show()

Actual outcome

Figure is plotted, but no keyboard input is handled/indicated.

Expected outcome

Figure is plotted, AND keyboard inputs are displayed.

Additional information

Does NOT happen in Matplotlib 3.4.1
Does NOT happen under Linux

Operating system

Windows

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

TkAgg

Jupyter version

No response

Installation

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions