我正在尝试使用python进行游戏(使用pygame),该游戏使用控制台菜单作为初始程序,然后打开由pygame生成的图形窗口(如果选择了相应的选项)。我有一个名为“bship.py”的文件,其中包含一个打开800x600窗口的典型pygame应用程序,当按下“1”时我无法弄清楚如何打开它......我尝试过“导入”功能但无济于事。这是代码!
print 'MAIN MENU'
print '----------'
print '\n'
print '1. Play'
print '2. Exit'
print '3. Credits\n\n\n\n\n\n'
menuAnswer = raw_input("> ")
if menuAnswer == '1':
#What is supposed to go here?
#How can I run my pygame file? :P
#"import bship" doesn't seem to work
elif menuAnswer == '2':
exit()
elif menuAnswer == '3':
import Credits
elif menuAnswer != ('1', '2', '3', '4'):
print 'Invalid selection...'
print 'learn to type, \n'
print 'Press ENTER when you are ready'
print 'to accept the repsonsibilities'
print 'of being a player...'
raw_input()
答案 0 :(得分:0)
if menuAnswer == '1':
game = subprocess.Popen([sys.executable, "bship.py"])
game.communicate()
使用Crayzeewulf的建议,我使用子进程模块来解决问题! woop woop:D