[Matplotlib-users] Key Press and Key Release Events in TkInter

Gregory Key gregk3172 at outlook.com
Tue Jan 31 16:05:22 EST 2017


I am running Python 3.5.2 and MatPlotLib 2.0.0 on Ubuntu 16.10.

I am developing a program that uses matplotlib embedded in tkinter to
plot vibration data in a bode plot, phase and amplitude versus rotor
speed. I adapted the data browser given in the matplotlib documentation
            as example 91.2 data_browser.py to browse the data. The
browser worked but I wanted to modify it so that holding down the next
or previous key would scroll through the data instead of having to
continously press and release the keys. My plan was to use the
key_press_event to start a timer which would call a scroll method and
then use the key_release event to stop the timer and stop scrolling. I
couldn't make this scheme work so I did some investigating on the
key_press_event and key_release_event in tkinter. I used example 91.5
keypress_demo.py given in the matplotlib documentation but I added a
key_release_event method to it. What I found was that the key events
don't work the way I would expect them to work. If you press and
release a key things work as expected. When a key is pressed the
key_press_event fires and when it is released the key_release_event
fires. If a key is pressed and held however the key_press_event fires
followed immediately by a key_release_event even though the key has not
been released. As long as the key is held down it will continue to fire
key_press_event followed by key_release_event. Is this the way it is
supposed to work?

Thanks
Greg Key


More information about the Matplotlib-users mailing list