Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I safely destroy a dialog window of a wxPython application?

I created a wxPython application which shows some messages on a dialog window. The dialog window is needed to be force-destroyed by the application before I click the dialog OK button. I used wx.lib.delayedresult to make the destroy call.

My code is:

import wx
dlg=wx.MessageDialog(somewindow,'somemessage')
from wx.lib.delayedresult import startWorker
def _c(d):
    dlg.EndModal(0)
    dlg.Destroy()
def _w():
    import time
    time.sleep(1.0)
startWorker(_c,_w)
dlg.ShowModal()

This can do what I desire to do while I got a error message below:

(python:15150): Gtk-CRITICAL **: gtk_widget_destroy: assertion `GTK_IS_WIDGET (widget)' failed

How do I "safely" destroy a dialog without clicking the dialog button?

like image 274
Akira Avatar asked Sep 08 '11 20:09

Akira


1 Answers

It has been a while since I have used wxWidgets but I think your dlg.Destroy() may be in the wrong place. Try moving it into the main thread.

import wx
dlg=wx.MessageDialog(somewindow,'somemessage')
from wx.lib.delayedresult import startWorker
def _c(d):
    dlg.EndModal(0)
def _w():
    import time
    time.sleep(1.0)
startWorker(_c,_w)
dlg.ShowModal()
dlg.Destroy()
like image 151
teambob Avatar answered Oct 13 '22 22:10

teambob