[英]How do I make an interactive application at the command line with Python, rather than just a script which returns output?
I would like to make a command line application in Python which, when I call its name, launches a new "mode" or interface at the command line, like launching Vim or Mutt, where key presses like 'q' or 'y' have specific functions - rather than just a script you run which returns some output.我想在 Python 中创建一个命令行应用程序,当我调用它的名称时,它会在命令行启动一个新的“模式”或界面,例如启动 Vim 或 Mutt,其中像“q”或“y”这样的按键有特定功能 - 而不仅仅是您运行的返回一些 output 的脚本。
How do I make this?我怎么做这个? Is there a specific library I would use for making this application?
是否有我将用于制作此应用程序的特定库? Or are there specific commands that tell the shell to display a kind of "window", and to listen for key presses and to execute commands on them?
或者是否有特定的命令告诉 shell 显示一种“窗口”,并监听按键并对其执行命令?
You can take a look at this question , there are some useful advices.你可以看看这个问题,有一些有用的建议。 In particular the best option seems to be the curses extension module .
特别是最好的选择似乎是curses 扩展模块。
I suggest also to check out this project that can give you an useful example to do what you ask, even if it uses a GUI kit.我还建议查看这个项目,它可以为您提供一个有用的示例来满足您的要求,即使它使用 GUI 工具包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.