I seem to have run into this problem with wx years ago -- destroying the widget that fed an event from a callback causes issues. As Chris suggested, the following seems to work, however:
import matplotlib.pyplot as plt import wx def close_figure(): plt.close() def onclick(event): if event.button==1: wx.CallAfter(close_figure) fig = plt.gcf() cid = fig.canvas.mpl_connect('button_press_event', onclick) plt.show() Mike On 10/15/2010 08:35 PM, Chris Barker wrote: > On 10/15/10 5:16 PM, Paul Ivanov wrote: > >> I want to do something like this: >> >> import matplotlib.pyplot as plt >> def onclick(event): >> if event.button==1: >> plt.close() >> fig = plt.gcf() >> cid = fig.canvas.mpl_connect('button_press_event', onclick) >> plt.show() >> >> I've tried several variations on this theme, but all of them cause >> crashes. Am I missing something? >> >> I'm using 1.0.0 with WXAgg >> >> thanks, >> >> > I don't know if MPL events do anything like this, but since you are > using wx, you could probably use wx.CallAfter() (or wx.CallLater(), call > one of those in your callback,a nd tehn have the function called close > the figure. > > -Chris > > > ------------------------------------------------------------------------------ > Download new Adobe(R) Flash(R) Builder(TM) 4 > The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly > Flex(R) Builder(TM)) enable the development of rich applications that run > across multiple browsers and platforms. Download your free trials today! > http://p.sf.net/sfu/adobe-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Space Telescope Science Institute Baltimore, Maryland, USA ------------------------------------------------------------------------------ Download new Adobe(R) Flash(R) Builder(TM) 4 The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly Flex(R) Builder(TM)) enable the development of rich applications that run across multiple browsers and platforms. Download your free trials today! http://p.sf.net/sfu/adobe-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users