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