[英]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的形式进行操作,那么可以使用大量系统,例如:
And more of them, and then loads more which aren't cross-platform. 还有更多,然后加载更多不是跨平台的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.