What is the purpose of dlg.Destroy() ?

Every example of I’ve seen of a wx.MessageDialog object being created is followed by that wx.MessageDialog object being destroyed.

dlg=wx.MessageDialog(self, ‘message’, “caption”, wx.OK)

dlg.ShowModal()

dlg.Destroy()

What is the purpose of dlg.Destroy() ? Isn’t dlg destroyed when someone clicks on the “OK” button, or the close icon in the top right of the dialog box? I wasn’t able to observe a difference omitting the line dlg.Destroy()

Hi,

Every example of I've seen of a wx.MessageDialog object being created is followed by that wx.MessageDialog object being destroyed.

dlg=wx.MessageDialog(self, 'message', "caption", wx.OK)
dlg.ShowModal()
dlg.Destroy()

What is the purpose of dlg.Destroy() ? Isn't dlg destroyed when someone clicks on the "OK" button, or the close icon in the top right of the dialog box? I wasn't able to observe a difference omitting the line dlg.Destroy()

A dialog should stay around after the user closes it that you can get at its data, but 'Destroy' needs to be called on it at some point otherwise it will prevent the application from closing.

As of 2.8.11.0 you can do the above like this:

with wx.MessageDialog(self, 'message', "caption", wx.OK) as dlg:
      if dlg.ShowModal() == wx.ID_OK:
         # do something with dlg values

http://www.wxpython.org/recentchanges.php

Werner

···

On 04/11/2013 06:25, RedHotChiliPepper wrote: