0

I successfully use Python 3.7 (or an earlier version) to do my graphics interface with Matplotlib. I use a definition to close the graphics window and exit my program by pressing ESC, make a screenshot by pressing F10 etc. It works fine using the definition below:

def quit_figure(event):
if event.key == 'escape':
   close(event.canvas.figure)
if event.key == 'f10':
   savefig('0.png',dpi=150)
if event.key == 'f1':
   sys.exit(0)

From time to time I decide to switch to the newest Python. Now it is 10.4 and suddenly all my old programs stopped working because don't respond to any keys ESC, F10, F1.

I haven't checked Python 3.8, 3.9 just jumped from 3.7 to 3.10.4 (32 and 64 any difference) changing anything in my programs. All works fine except for the reaction on the keyboard.

I have checked the Internet - no answer, installed and reinstalled Python 10.4 on a few computers, installed it on fresh Windows 10 11 etc. on Python 3.7 my programs work on 10.4 works except keyboard reaction. I must operate a mouse to exit my program.

I would be grateful for any suggestions.

L. Flis
  • 13
  • 1
  • 4
  • This is a reported bug that will be solved when matplotlib `3.5.2` is released (hopefully this month https://github.com/matplotlib/matplotlib/issues/22827). Until it's released, as a workaround it's suggested to use `canvas.get_tk_widget().focus_set()`. In your code, just before the first `if` statement you could call `event.get_tk_widget().focus_set()` or call this same mehtod on the event before `quit_figure` is used. You could also change your matplotlib backend (https://stackoverflow.com/questions/3285193/how-to-change-backends-in-matplotlib-python) if you don't mind not using `Tkinter`. – mtzd May 01 '22 at 22:38

0 Answers0