WXPYTHON push button call a frame

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Thu Jul 5 20:04:32 CEST 2007

Marcpp schreef:
> Hi I need to call a widget from a button in WXPYTHON. I've tried to
> this from a function like this, but when push the button, the program
> opens a window and do error.
> Any idea?
> .....
>     def DialogRRHH(self,event):
>         prog = wx.PySimpleApp(0)
>         wx.InitAllImageHandlers()
>         DialogRRHH = MTRRHH(None, -1, "")
>         prog.SetTopWindow(DialogRRHH)
>         DialogRRHH.Show()
>         prog.MainLoop()
> class MTRRHH(wx.Frame):
> .......
> if __name__ == "__main__":
>     app = wx.PySimpleApp(0)
>     wx.InitAllImageHandlers()
>     tasques = tasques(None, -1, "")
>     app.SetTopWindow(tasques)
>     tasques.Show()
>     app.MainLoop()

In DialogRRHH() you create a new application object with a new event 
loop, while you already have one running. wxPython should have only one 
application object though; otherwise there conflicts between the 
different event loops. Also you don't need to call 
wx.InitAllImageHandlers() again.

It seems to me that in DialogRRHH() you want to create a dialog and wait 
until the user closes it. In that case, it should look more or less like 
this (beware, I'm not a wxPython expert myself):

     def DialogRRHH(self, event):
         DialogRRHH = MTRRHH(None, -1, "")

Also, in that case MTRRHH should be a wxDialog, not a wxFrame.

In case you want to show MTRRHH without waiting for the user to close 
it, use DialogRRHH.Show() instead of .ShowModal(). I think MTRRHH can be 
either a wxDialog or a wxForm in that case.

If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

More information about the Python-list mailing list