wxPython crashes when run

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kdt
    New Member
    • Mar 2007
    • 50

    wxPython crashes when run

    Hi,

    My GUI keeps crashing on the second time it runs. It doesn't come up with any useful error messages, just says "there was a problem". I've narrowed the offending code to the following.

    I'm running wxpython on windows xp.

    cheers

    [CODE=python]

    import wx

    class myFrame(wx.Fram e):
    def __init__(self, parent, id, title):
    wx.Frame.__init __(self, parent, id, title, size=(250, 150))

    menubar = wx.MenuBar()
    file = wx.Menu()
    quit = wx.MenuItem(fil e, 1, '&Quit\tCtrl+Q' )
    file.AppendItem (quit)

    self.Bind(wx.EV T_MENU, self.OnQuit, id=1)

    menubar.Append( file, '&File')
    self.SetMenuBar (menubar)

    self.Centre()
    self.Show(True)

    def OnQuit(self, event):
    self.Close()

    class MyApp(wx.App):
    def OnInit(self):
    frame =myFrame(None,-1,"frame test")
    self.SetTopWind ow(frame)

    print "Print statements go to this stdout window by default."

    frame.Show(True )
    return True

    app = MyApp(False)
    app.MainLoop()

    [/CODE]
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    I ran this successfully on my machine many times in a row with no errors.
    The only thing that I see as a "mistake" is using a literal for the ID of the menu item. A better method would be to have wx give you IDs at the module level:[CODE=python]wxID_MYMENUITEM S0 = wx.NewId()[/CODE]The create the menu item and Bind() using that ID.

    The reason that it is a mistake to use literals as IDs is that many IDs are used internally by wx. wx.NewId() will always return a usable ID.

    Comment

    • kdt
      New Member
      • Mar 2007
      • 50

      #3
      Originally posted by bartonc
      I ran this successfully on my machine many times in a row with no errors.
      The only thing that I see as a "mistake" is using a literal for the ID of the menu item. A better method would be to have wx give you IDs at the module level:[CODE=python]wxID_MYMENUITEM S0 = wx.NewId()[/CODE]The create the menu item and Bind() using that ID.

      The reason that it is a mistake to use literals as IDs is that many IDs are used internally by wx. wx.NewId() will always return a usable ID.
      Thanks Bartonc, resolved now. :)

      Comment

      Working...