如何在matplotlib中检测双击事件? [英] How can I detect double click events in matplotlib?
问题描述
import matplotlib.pyplot as plt
def onclick(event):
print event.button
fig = plt.figure()
connection_id = fig.canvas.mpl_connect('button_press_event',onclick)
plt.show()
使用这样的结构,我遇到双击点击 onclick()
handler three 次。我想它正在接收这两个点击次数,还有一个额外的双击事件。如何更改此行为,以便事件处理程序不会触发双击事件?或者,如何从事件实例中检测它们,以便我可以忽略这些双击?
注意: button_release_event
没有这个问题,但我想在 button_press_event
当我有matplotlib版本1.1rc时,我无法捕获dblclick事件。
以后,我为matplotlib 1.2编写了代码,这是可以的。
import matplotlib.pyplot as plt
fig = plt.figure()
def onclick(event):
如果event.dblclick:
print event.button
connection_id = fig.canvas.mpl_connect 'button_press_event',onclick)
plt.show()
import matplotlib.pyplot as plt
def onclick(event):
print event.button
fig = plt.figure()
connection_id = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
With a construct like this, I have the problem of double-clicks hitting onclick()
handler three times. I guess that it is receiving both the clicks, and an additional double-click event. How can I change this behaviour so that the event handler is not fired for double-click events? Or, alternatively, how can I detect them from the event instance so that I can ignore those double-clicks?
note: button_release_event
does not have this problem, but I want to fire on the button_press_event
When i had matplotlib version 1.1rc, i was not able to catch dblclick event. Later, I wrote code for matplotlib 1.2 and that is ok
import matplotlib.pyplot as plt
fig = plt.figure()
def onclick(event):
if event.dblclick:
print event.button
connection_id = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
这篇关于如何在matplotlib中检测双击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!