简体   繁体   English

如何使用 Python 在命令行中创建交互式应用程序,而不仅仅是返回 output 的脚本?

[英]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.

相关问题 在 Python 脚本中包装交互式命令行应用程序 - Wrapping an interactive command line application in a Python script 在 Python 中,如何使用交互式命令行(和可视断点?)进行调试 - In Python, how do I debug with an interactive command line (and visual breakpoints?) 如何打包一个接受命令行参数并且还具有依赖关系的 Python 脚本? - How do I package a single python script which takes command line arguments and also has dependencies? 如何在WPF应用程序中从命令行运行Python脚本 - How do I run a Python script from command line in a WPF application 如何使漫游器说由变量而不是回复命令激活的消息? - How do I make a bot say a message activated by a variable rather than a reply command? 如何使这个 Python 程序具有交互性? - How do I make this Python program interactive? 如何使用csv使Python读取一行中的第一个单词而不是第一个字符? - How can I make Python using csv read the first word in a line rather than the first character? 如何检索上一个命令的输出并将其保存在Python交互式shell中的变量中? - How do I retrieve the output of a previous command and save it in a variable inside the Python interactive shell? 如何在Win32上的Emacs中运行交互式命令行Python应用程序? - How do I run an interactive command line Python app inside of Emacs on Win32? 如何优化python代码以读取一批多行而不是一次读取一行? - How do I optimize the python code to read a batch of multiple lines rather than one line at a time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM