我正在尝试了解运行以下代码后未触发on_key
的原因。我知道将V()
更改为v = V()
或将on_key(self, event)
定义为静态方法后,on_key
将被正确调用。但为什么下面的代码不起作用?
谢谢。
import matplotlib.pyplot as plt
class V:
def __init__(self):
fig = plt.figure()
fig.canvas.mpl_connect('key_press_event', self.on_key)
def on_key(self, event):
print "user pressed =>", event.key
V()
plt.show()