Closed
Description
Bug report
Bug summary
Calling input
inside a key_press_event
results either in a RuntimeError or causes the terminal and canvas to freeze. Presumably, this is because the input to input
triggers further on_key_press
calls (although this issue also appears to happen when the figure is not in focus so I am actually not sure if that is the reason). I am looking for a work around.
Code for reproduction
import matplotlib.pyplot as plt
plt.ion()
fig, ax = plt.subplots()
def on_key_press(event):
if event.key == 'enter':
ans = input('Provide some text to print and press enter:\n')
# ans = 'foo'
ax.text(event.xdata, event.ydata, ans)
fig.canvas.draw_idle()
cid = fig.canvas.mpl_connect('key_press_event', on_key_press)
Actual outcome
Traceback (most recent call last):
File "/home/paul/.virtualenvs/test3_netgraph/lib/python3.5/site-packages/matplotlib/cbook/__init__.py", line 389, in process
proxy(*args, **kwargs)
File "/home/paul/.virtualenvs/test3_netgraph/lib/python3.5/site-packages/matplotlib/cbook/__init__.py", line 227, in __call__
return mtd(*args, **kwargs)
File "/home/paul/src/netgraph/netgraph/input_block.py", line 16, in on_key_press
ans = input('Provide some text to print and press enter:\n')
RuntimeError: can't re-enter readline
Expected outcome
The expected outcome can be simulated by commenting out the input call and uncommenting the ans = 'foo'
line in the MWE.
Matplotlib version
- Operating system: Ubuntu 17.04
- Matplotlib version: 2.1.0
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.5.3
- Jupyter version (if applicable): na
- Other libraries: numpy, ipython and their dependencies
Installed everything via pip.
Metadata
Metadata
Assignees
Labels
No labels