wxPython问题;未定义全局名称NULL

我正在尝试激活wxPython的教程代码,
当我告诉它从wxPython.wx导入*时,它工作正常
但由于包裹有误,
我已经按照要求将导入更改为WX
并将所有的wxthing更改为wx.某物
但当我启动它时,它给了我一个错误,说
回溯(最近一次呼叫):
文件"C:/Python25/SD",第32行,位于
App=MyApp(0)
文件"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",第7913行,位于__init__中
Sel._BootstrapApp()
文件"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",第7487行,位于_BootstRapApp中
Return_core_.PyApp__BootstrapApp(*args,**kwargs)
OnInit中的文件"C:/Python25/SD",第27行
Frame=MyFrame(空,-1,"来自wxPython的Hello")
NameError:未定义全局名称'Null'

选择 | 换行 | 行号
  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.  

我是不是做错了什么?

# 回答1


也许,可以尝试将"NULL"更改为"None".此外,不要在Frame.Show()方法中传递"true".最后,您可以返回"1"作为OnInit()函数的布尔值.
修改后的代码为:

选择 | 换行 | 行号
  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()

我已经检查过它的工作情况,但如果你的情况不好,请一定要告诉我.

# 回答2


是的,现在工作正常,谢谢你
# 回答3


很高兴知道NetWatcher,代码现在可以很好地为您工作.:)

标签: python

添加新评论