Skip to content

[Bug]: Event handling with input in callback function #30419

Description

@ljlamarche

Bug summary

When using a button click event handler, if the callback function includes the input function, the figure automatically closes when the callback function finishes.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
ax.plot(np.random.rand(10))

def onclick(event):
    print(f'click: x={event.x}, y={event.y}')
    info = input('Enter some information about this point: ')  # Comment out this line
    print(info)                                                # Comment out this line

cid = fig.canvas.mpl_connect('button_press_event', onclick)

plt.show()

Actual outcome

After a single event and iteration of the onclick callback function, the figure automatically closes without giving the user the opportunity to click on more points.

Screen.Recording.2025-08-12.at.5.17.43.PM.mov

Expected outcome

The figure should remain open and allow the user to click on many points until the user explicitly closes it. This is the standard behavior when the two lines indicated in the MWE related to the input function are commented out.

Screen.Recording.2025-08-12.at.5.23.06.PM.mov

Additional information

No response

Operating system

OS/X

Matplotlib Version

3.10.3

Matplotlib Backend

macosx

Python version

Python 3.13.5

Jupyter version

4.4.5

Installation

pip

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