我的理解是:通常,当发生错误时,它通过所有调用函数抛出,然后显示在控制台中。现在有一些软件包可以自己处理错误,特别是与GUI相关的软件包通常不会显示错误,只是继续执行。如何在mpl_connect()回调函数中显示错误消息
我们如何重写这种行为?当我编写GUI功能时,我希望看到错误!我找到了this post这里解释了如何为Tkinter做这件事。这怎么能在Matplotlib中完成?
示例代码:
import matplotlib.pyplot as plt
def onclick(event):
print(event.x, event.y)
raise ValueError('SomeError') # this error is thrown but isn't displayed
fig = plt.figure(5)
fig.clf()
try: # if figure was open before, try to disconnect the button
fig.canvas.mpl_disconnect(cid_button)
except:
pass
cid_button = fig.canvas.mpl_connect('button_press_event', onclick)