Python matplotlib.pyplot:on_key不是使用canvas.mpl_connect触发的

时间:2015-03-07 06:18:17

标签: python matplotlib onkeydown

我正在尝试了解运行以下代码后未触发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()

0 个答案:

没有答案