我在按书上编译python 源码时,老是提示错误,虽然输入正确,编译不成功(eclisp工具)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我在按书上编译python 源码时,老是提示错误,虽然输入正确,编译不成功(eclisp工具)相关的知识,希望对你有一定的参考价值。
python编译代码老是出现下面错误:
Traceback (most recent call last):
File "C:\eclipse\test3\src\menueditor.py", line 31, in <module>
frame = MainWindow(None, "Sample editor")
File "C:\eclipse\test3\src\menueditor.py", line 19, in __init__
filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
NameError: global name 'filemenu' is not defined
代码如下:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A Statusbar in the bottom of the window
# Setting up the menu.
filemenu= wx.Menu()
# wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets.
filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
self.Show(True)
app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()
我自己输入的,编译有错误代码:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A Statusbar in the bottom of the window
#Setting up the menu
filemunu=wx.Menu()
filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
#Create the menubar
menuBar=wx.MenuBar()
menubar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
self.Show(True)
app=wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()
filemunu=wx.Menu()
filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
看来没问题的是源代码,你自己写的还是有问题,filemenu都没有定义,为什么呢,因为你定义的是filemunu而不是filemenu。。。。。。 参考技术A 这不是写了么NameError: global name 'filemenu' is not defined
'filemenu' 这个全局变量未定义 参考技术B filemunu=wx.Menu()
这句是不是写错了
改
filemenu=wx.Menu()
以上是关于我在按书上编译python 源码时,老是提示错误,虽然输入正确,编译不成功(eclisp工具)的主要内容,如果未能解决你的问题,请参考以下文章
vs2013 在按F5调试时,总是提示 “项目已经过期”的解决方案
python3.5.4安装时老是弹出api-ms-win-crt-runtime-|1-1-0.dll错误的解决方法