[wxPython-users] Re: how do I start PyCrust?

Robin Dunn robin at alldunn.com
Tue Jun 5 19:23:00 PDT 2007


7stud wrote:
> Cody Precord <codyprecord <at> gmail.com> writes:
> 
>> pywrap is probably just not on your path,
>>
>> try:
>> $ /usr/local/bin/pywrap
>>
> 
> Thanks.  However, I couldn't get the example on p. 102 to work.
> 
> 1)  This is the example code:
> ----
> import wx
> 
> class MyFrame(wx.Frame):
>     pass
> 
> class MyApp(wx.App):
>     def OnInit(self):
>         self.frame = MyFrame(None, -1, "Test")
>         self.frame.Show()
>         self.SetTopWindow(self.frame)
>         return True
> 
> app = MyApp()
> app.MainLoop()
> ------
> 
> 2) I did a pywrap like this:
> 
> $ /usr/local/bin/pywrap wxPython1.py
> 
> 3) The "Test" window appeared.  I closed the Test window out, and then 
> the pycrust window appeared along with another Test window hidden behind it.
> 

For pywrap to work you need to not automatically create the app and run 
the MainLoop when the module is imported.  Try it like this:


import wx

class MyFrame(wx.Frame):
     pass

class MyApp(wx.App):
     def OnInit(self):
         self.frame = MyFrame(None, -1, "Test")
         self.frame.Show()
         self.SetTopWindow(self.frame)
         return True

if __name__ == '__main__':
     app = MyApp()
     app.MainLoop()


This way pywrap can import the module and then create the instance of 
the application object itself.  It also calls MainLoop.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list