Python中同时监听网络事件和键盘输入

发布于 2024-12-10 04:43:23 字数 236 浏览 2 评论 0原文

我想编写一个(GUI)应用程序,它既监听键盘事件(客户端生成的事件)又监听网络端口(服务器端生成的事件)。我可以使用一些关于如何做到这一点的高级建议。一些附加信息: - 我正在使用 GUI 的 wxPython 模块 - 我可以将套接字设置为非阻塞模式,但这样我必须通过继续执行recv()命令来不断轮询套接字。我之前这样做过,我记得这使用了相当多的资源 - 我可以使用线程模块,但由于我不熟悉它,我尝试避免这种情况,但也许我不能 如有建议,我们将不胜感激。

I want to write an (GUI) application that listens both to keyboard events (client side generated events) and to a network port (server side generated events). I could use some high level advice on how to do this. Some additional info:
- I am using the wxPython module for the GUI
- I could set the socket in non-blocking mode, but this way I have to keep polling the socket by keeping executing the recv() command. I did this earlier and I can recall that this used considerable resources
- I could use the thread module, but since I am not familiar with it, I try to avoid this, but maybe I can't
Advice would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贩梦商人 2024-12-17 04:43:24

wxPython确实有关键事件。以下是有关该主题的 wxPython 文档页面: http://www.wxpython .org/docs/api/wx.KeyEvent-class.html

wxPython 并没有将每一个东西都包装在 wxWidgets 中。开发人员认为他们不需要包装 Python 本身已经得到大力支持的东西。因此,请参阅 Python 的套接字支持

如果你想得到真的很重,看看 Twisted 框架。有几篇关于将其与 wxPython 一起使用的文章:

wxPython does have key events. Here are the wxPython docs page on the subject: http://www.wxpython.org/docs/api/wx.KeyEvent-class.html

wxPython doesn't wrap every single thing in wxWidgets. The developers didn't think that they needed to wrap stuff that already had great support in Python itself. Thus, see Python for its socket support

And if you want to get really heavy, look into the Twisted framework. There are several articles on using it with wxPython:

叹沉浮 2024-12-17 04:43:24

我不是wx专家。你能使用wx的原生事件驱动机制吗?按键肯定会有一个事件。 Wx 有一个套接字类 wxSocketClient() ,它可以将低级套接字事件(数据就绪、关闭等)转换为 wx 事件。

I am not a wx expert. Could you use wx's native event driven mechanisms? The keypress would certainly have an event. Wx has a socket class wxSocketClient() that could translate the low level socket events (data ready, closed, etc) into a wx event.

随风而去 2024-12-17 04:43:24

文档中有 wxKeyEvent 。用它来捕获密钥并使用 Socket 通过网络发送它或做任何你想做的事情!对于套接字,请参阅此粘帖。它是C++,但它会给你一个更好的想法!

There is wxKeyEvent in Docs. Use that to catch the keys and Socket to send it via a network or do whatever you want to do! For socket see this sticky. It is C++ but it will give you a better Idea!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文