Get The Key Value When Calling Matplolib Pyplot Waitforbuttonpress()
matplotlib pyplot has a function called waitforbuttonpress() which will return either True or False depending on whether a keyboard or mouse event is received within a graph. As su
Solution 1:
I don't think that's directly possible, but you can get the key value from a key_press_event
, which will be fired at the same time as waitforbuttonpress()
:
import matplotlib.pyplot as plt
the_key = None
def press(event):
global the_key
the_key = event.key
plt.figure()
plt.plot([1, 4, 6])
plt.gcf().canvas.mpl_connect('key_press_event', press)
while not plt.waitforbuttonpress(): pass # ignore mouse events use by zomming ...
print("You pressed: ", the_key)
Post a Comment for "Get The Key Value When Calling Matplolib Pyplot Waitforbuttonpress()"