我想打开.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打开了
Traceback(最近一次调用):
文件“ D:\ Python \ Python Projects \ Project \ MenuWindow.py”,第48行,位于OnNewGame中
new = GameFrame(parent = None,id = -1)
NameError:全局未定义名称“ GameFrame”
您导入游戏,并且GameFrame是游戏的一部分,因此您应该输入
new = game.GameFrame(parent=None, id=-1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句