我正在开发一个基于文本的游戏,我通过双击我的顶级脚本TopLevel.py
来运行。
我想在这个脚本中打开两个终端。在一个终端中,主游戏将运行在造成伤害和使用法术等地方。在另一个终端,我想显示一个命令列表,用户可以输入,我希望后一个留在那里,不关闭,直到游戏结束。我不打算向您展示整个顶层脚本(它太长了),但这基本上是我想要实现的:
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()
函数作为参数传递给第二个终端来显示它的内容?如有任何帮助,我们将不胜感激:)
你应该先把你的第二个程序转换成.exe,这个程序会显示用户命令。假设您将其保存为
usercommands.exe
,然后在主脚本中使用此项打开该项当您运行主文件时,它将打开另一个控制台窗口,该窗口运行
usercommands.exe
。在注释
编辑
现在,我们有了一些咒语,
^{pr2}$usercommands
必须使用这些咒语变量,然后向我们展示一些组合。为此,我们必须将您的第一个文件导入usercommands
脚本。它会喜欢这样的算法应该是这样的,您将
usercommands.py
转换为.exe,然后它将按您想要的方式工作我猜,在您尝试之前我们现在不能;)一个Python脚本可以通过
subprocess
生成另一个与之并行运行的脚本。然后,派生的进程可以在一个简单的基于tkinter
的窗口中显示任何通过管道传输到它的文本(通过普通的print
语句或调用)有关更多信息,请参阅我的this answer中的errorwindow
模块。在原始脚本如何开始可能并不重要。我个人在从命令shell和其他基于
tkinter
的应用程序启动的应用程序中都使用过它,所以从powershell启动您的应用程序应该可以。我相信,这个模块的最初作者使用的是Linux或类似的东西。在相关问题 更多 >
编程相关推荐