简体   繁体   English

如何在不等待Python的情况下接受用户输入

[英]How to accept user input without waiting in Python

I'm creating an IRC bot and I want to be able to constantly receive from my buffer, but at the same time if I type a command into the console I want it to be readily accepted. 我正在创建一个IRC机器人,我希望能够不断从我的缓冲区接收,但同时如果我在控制台中输入一个命令,我希望它能够被接受。 So far I have a infinite loop that constantly checks the input buffer of the IRC server, but I don't know how I can receive input from the console without freezing everything else. 到目前为止,我有一个无限循环,不断检查IRC服务器的输入缓冲区,但我不知道如何从控制台接收输入而不冻结其他所有内容。

The best thing to do in this case is to use some sort of UI library that contains an event loop. 在这种情况下,最好的办法是使用某种包含事件循环的UI库。 You poll this event loop for things that happen including keys pressed and mouse clicks. 您可以轮询此事件循环以查找发生的事情,包括按下的键和鼠标单击。

If you want to do this in a terminal, there is Urwid . 如果你想在终端上做这个,有Urwid If you want to do it as a GUI there are tons of systems available, like: 如果您想以GUI的形式进行操作,那么可以使用大量系统,例如:

  • Gnome 地精
  • GTK GTK
  • KDE KDE
  • Tcl/Tk 的Tcl / Tk
  • Qt4 Qt4的
  • Kivy Kivy

And more of them, and then loads more which aren't cross-platform. 还有更多,然后加载更多不是跨平台的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在不等待用户输入的情况下打印 python 数据表 - Is there a way to print python datatable without waiting for user input at the end 继续执行Python更新脚本,而无需等待用户输入 - Continue execution of a Python update script without waiting for user input Python:如何判断输入文件是否有输入待处理而无需等待 - Python: how to tell if input file has input pending without waiting 如何停止subprocess.Popen在python中等待用户输入 - How to stop subprocess.Popen waiting for user input in python 如何在不停止脚本和等待用户表单输入的情况下,将变量从Flask Form更新为连续运行的python脚本? - How do I update variable from Flask Form to a continuously running python script, without the script stopping and waiting for the user form input? 如何在Python的多维列表中接受用户输入的字符串? - How to accept user input string in multi dimension list in Python? 如何通过单击 Python 中的 Tkinter 按钮接受图像作为用户输入? - How to accept image as user input by clicking on Tkinter button in Python? Python如何只接受用户输入的某些单词 - Python How to accept only certain words with user input 如何在Python的多维列表中接受用户输入? - How to accept user input in multi dimension list in Python? 如何打印倒数计时器并同时接受用户输入(python)? - How to print countdown timer and accept user input at the same time (python)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM