wxPython problem; global name NULL is not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Netwatcher
    New Member
    • Sep 2008
    • 58

    #1

    wxPython problem; global name NULL is not defined

    im try to activate the tutorial code for wxPython,
    it is working properly when i tell it to import * from wxPython.wx
    but with an error about the package,
    i've done as i was told to change the import to wx
    and change all wxsomething to wx.something
    but when i start it it gives me an error that say

    Traceback (most recent call last):
    File "C:/Python25/Sd", line 32, in <module>
    app = MyApp(0)
    File "C:\Python25\Li b\site-packages\wx-2.8-msw-unicode\wx\_cor e.py", line 7913, in __init__
    self._Bootstrap App()
    File "C:\Python25\Li b\site-packages\wx-2.8-msw-unicode\wx\_cor e.py", line 7487, in _BootstrapApp
    return _core_.PyApp__B ootstrapApp(*ar gs, **kwargs)
    File "C:/Python25/Sd", line 27, in OnInit
    frame = MyFrame(NULL, -1, "Hello from wxPython")
    NameError: global name 'NULL' is not defined


    Code:
    import wx
    ID_ABOUT = 101
    ID_EXIT  = 102
    
    class MyFrame(wx.Frame):
        def __init__(self, parent, ID, title):
            wx.Frame.__init__(self, parent, ID, title,
                             wx.DefaultPosition, wx.Size(200, 150))
            self.CreateStatusBar()
            self.SetStatusText("This is the statusbar")
    
            menu = wx.Menu()
            menu.Append(ID_ABOUT, "&About",
                        "More information about this program")
            menu.AppendSeparator()
            menu.Append(ID_EXIT, "E&xit", "Terminate the program")
    
            menuBar = wx.MenuBar()
            menuBar.Append(menu, "&File");
    
            self.SetMenuBar(menuBar)
    
    
    class MyApp(wx.App):
        def OnInit(self):
            frame = MyFrame(NULL, -1, "Hello from wxPython")
            frame.Show(true)
            self.SetTopWindow(frame)
            return true
    
    app = MyApp(0)
    app.MainLoop()
    am i doing something wrong?
  • iamgame
    New Member
    • Sep 2008
    • 4

    #2
    Originally posted by Netwatcher
    am i doing something wrong?
    Perhaps, try changing "NULL" to "None". Also, do not pass "true" in the frame.Show() method. And lastly, you can return "1" as the boolean value for OnInit() function.

    Modified code is:

    [CODE=python]import wx
    ID_ABOUT = 101
    ID_EXIT = 102

    class MyFrame(wx.Fram e):
    def __init__(self, parent, ID, title):
    wx.Frame.__init __(self, parent, ID, title,
    wx.DefaultPosit ion, wx.Size(200, 150))
    self.CreateStat usBar()
    self.SetStatusT ext("This is the statusbar")

    menu = wx.Menu()
    menu.Append(ID_ ABOUT, "&About",
    "More information about this program")
    menu.AppendSepa rator()
    menu.Append(ID_ EXIT, "E&xit", "Terminate the program")

    menuBar = wx.MenuBar()
    menuBar.Append( menu, "&File");

    self.SetMenuBar (menuBar)


    class MyApp(wx.App):
    def OnInit(self):
    frame = MyFrame(None, -1, "Hello from wxPython")
    frame.Show()
    self.SetTopWind ow(frame)
    return 1

    app = MyApp(0)
    app.MainLoop()[/CODE]

    I have checked for its working, but do let me know if it doesn't in your case.

    Comment

    • Netwatcher
      New Member
      • Sep 2008
      • 58

      #3
      Yep, it's working alright now, thank you

      Comment

      • iamgame
        New Member
        • Sep 2008
        • 4

        #4
        Nice to know Netwatcher that the code is working alright for you now. :)

        Comment

        Working...