【发布时间】:2014-05-04 13:29:04
【问题描述】:
我想打开 .py 文件——我发现了——然后从打开的文件运行新框架。这是文件 MenuWindow 中的代码:
def OnNewGame(self,event):
play = False
nameofplr = wx.GetTextFromUser('Enter your name:', 'NEW GAME')
subor=open("Save/savegame.txt","a")
subor.write( "\n" + nameofplr)
subor.close()
savegame=open("Save/" + nameofplr + ".prjct", "w+")
savegame.close()
play = True
if (play == True):
sys.path.insert(0, './bin')
import game
new = GameFrame(parent=None, id=-1)
new.Show()
self.Close()
这是来自 game.py 的代码:
print "game.py opened"
导入 wx
类 GameFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self, parent, id, "Project", size=(860, 640))
wx.Frame.CenterOnScreen(self)
输出打印 game.py 打开所以它打开文件,但为什么它不创建新框架?
这是输出:
game.py 打开
回溯(最近一次通话最后一次):
文件“D:\Python\Python Projects\Project\MenuWindow.py”,第 48 行,在 OnNewGame
新 = GameFrame(父=None, id=-1)
NameError:未定义全局名称“GameFrame”
【问题讨论】: