我正在研究一个基于文本的游戏,通过双击我的顶级脚本即TopLevel.py
来运行。 我正在寻找一种方法来在此脚本中打开两个终端。在一个终端中,主游戏将运行在造成伤害并且使用法术等情况下。在另一个终端中,我想显示用户可以键入的命令列表,并且我希望后者停留在那里并且在比赛结束前不能关闭。我不会告诉你整个顶层脚本(实在是太长了),但是这基本上是我想达到什么:如何用一个python脚本打开一个powershell终端?
def displayCommands(hero):
list_of_commands = []
#this contains all my commands that the user can type in
def main():
hero = Hero() #make hero instance
enemy = Enemy() #make and enemy instance
a_game = TopLevel(hero,enemy) #create game engine
a_game.play() #start game
#implement code here to open another terminal
#and display user commands in there
有没有一种方法,我可以在这个脚本打开另一个终端,并通过displayCommands()
作为参数在第二个终端显示其内容?任何帮助将不胜感激:)
第一个终端如何打开,它为什么需要成为一个PowerShell控制台? – martineau
我问,因为有一种方法可以让一个Python脚本通过'subprocess'并行产生另一个脚本,它将显示通过'tkinter'窗口传递给它的文本输出 - 参见[this answer]中的errorwindow模块(http: //stackoverflow.com/a/18091356/355230)。 – martineau
我appologise我只想打开一个终端与脚本。 (编辑问题)。我通过在Windows PowerShell中键入'python TopLevel.py'运行第一个脚本。然后,我想在从TopLevel.py打开的第二个终端中显示“list_of_commands”的内容。没有具体的理由使用PowerShell,我刚刚习惯了阅读_Learn Python The Hard Way_。 – Loupi