0
我试图在python(使用pygame)中使用控制台菜单作为初始程序,然后打开由pygame生成的图形窗口(如果相应的选项)被选中。我有一个名为“bship.py”的文件,其中包含一个打开800x600窗口的典型pygame应用程序,当按下'1'时我无法弄清楚如何打开它...我试过了“导入”功能但无济于事。这是代码!将控制台应用程序链接到python中的图形应用程序
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()
想想如何在不使用上述菜单的情况下运行'bship.py'。然后阅读['subprocess'](http://docs.python.org/2/library/subprocess.html)模块。你可以运行'bship.py'作为一个子进程。 – crayzeewulf 2013-03-07 23:59:46
是的,这似乎工作......谢谢crayzeewulf:D – Moshi 2013-03-08 00:40:27