如何在不等待Python的情况下接受用户输入 [英] How to accept user input without waiting in Python

查看:223
本文介绍了如何在不等待Python的情况下接受用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个IRC机器人,希望能够不断从缓冲区中接收消息,但是同时如果我在控制台中键入命令,我希望它可以被接受.到目前为止,我有一个无限循环,不断检查IRC服务器的输入缓冲区,但是我不知道如何在不冻结其他所有内容的情况下从控制台接收输入.

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. 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.

推荐答案

在这种情况下,最好的办法是使用某种包含事件循环的UI库.您可以在此事件循环中轮询发生的事情,包括按下的键和单击的鼠标.

The best thing to do in this case is to use some sort of UI library that contains an event loop. You poll this event loop for things that happen including keys pressed and mouse clicks.

如果您想在终端中执行此操作,请使用 Urwid .如果您想将其作为GUI进行操作,则可以使用大量的系统,例如:

If you want to do this in a terminal, there is Urwid. If you want to do it as a GUI there are tons of systems available, like:

  • 侏儒
  • GTK
  • KDE
  • Tcl/Tk
  • Qt4
  • 基辅

其中的更多,然后加载更多的不是跨平台的.

And more of them, and then loads more which aren't cross-platform.

这篇关于如何在不等待Python的情况下接受用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆