467,920 Members | 1,256 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,920 developers. It's quick & easy.

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\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7913, in __init__
self._BootstrapApp()
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7487, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:/Python25/Sd", line 27, in OnInit
frame = MyFrame(NULL, -1, "Hello from wxPython")
NameError: global name 'NULL' is not defined


Expand|Select|Wrap|Line Numbers
  1. import wx
  2. ID_ABOUT = 101
  3. ID_EXIT  = 102
  4.  
  5. class MyFrame(wx.Frame):
  6.     def __init__(self, parent, ID, title):
  7.         wx.Frame.__init__(self, parent, ID, title,
  8.                          wx.DefaultPosition, wx.Size(200, 150))
  9.         self.CreateStatusBar()
  10.         self.SetStatusText("This is the statusbar")
  11.  
  12.         menu = wx.Menu()
  13.         menu.Append(ID_ABOUT, "&About",
  14.                     "More information about this program")
  15.         menu.AppendSeparator()
  16.         menu.Append(ID_EXIT, "E&xit", "Terminate the program")
  17.  
  18.         menuBar = wx.MenuBar()
  19.         menuBar.Append(menu, "&File");
  20.  
  21.         self.SetMenuBar(menuBar)
  22.  
  23.  
  24. class MyApp(wx.App):
  25.     def OnInit(self):
  26.         frame = MyFrame(NULL, -1, "Hello from wxPython")
  27.         frame.Show(true)
  28.         self.SetTopWindow(frame)
  29.         return true
  30.  
  31. app = MyApp(0)
  32. app.MainLoop()
  33.  
am i doing something wrong?
Sep 14 '08 #1
  • viewed: 16650
Share:
3 Replies
iamgame
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:

Expand|Select|Wrap|Line Numbers
  1. import wx
  2. ID_ABOUT = 101
  3. ID_EXIT  = 102
  4.  
  5. class MyFrame(wx.Frame):
  6.     def __init__(self, parent, ID, title):
  7.         wx.Frame.__init__(self, parent, ID, title,
  8.                          wx.DefaultPosition, wx.Size(200, 150))
  9.         self.CreateStatusBar()
  10.         self.SetStatusText("This is the statusbar")
  11.  
  12.         menu = wx.Menu()
  13.         menu.Append(ID_ABOUT, "&About",
  14.                     "More information about this program")
  15.         menu.AppendSeparator()
  16.         menu.Append(ID_EXIT, "E&xit", "Terminate the program")
  17.  
  18.         menuBar = wx.MenuBar()
  19.         menuBar.Append(menu, "&File");
  20.  
  21.         self.SetMenuBar(menuBar)
  22.  
  23.  
  24. class MyApp(wx.App):
  25.     def OnInit(self):
  26.         frame = MyFrame(None, -1, "Hello from wxPython")
  27.         frame.Show()
  28.         self.SetTopWindow(frame)
  29.         return 1
  30.  
  31. app = MyApp(0)
  32. app.MainLoop()
I have checked for its working, but do let me know if it doesn't in your case.
Sep 14 '08 #2
Yep, it's working alright now, thank you
Sep 14 '08 #3
iamgame
Nice to know Netwatcher that the code is working alright for you now. :)
Sep 15 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Elmar Haneke | last post: by
5 posts views Thread by NetKev | last post: by
8 posts views Thread by Evan | last post: by
3 posts views Thread by barronmo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.