从PyQt事件循环中执行Python代码 [英] Execute Python code from within PyQt event loop

查看:240
本文介绍了从PyQt事件循环中执行Python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试使用PyQt构建的gui,我希望能够使用PyQt事件循环启动后执行的python代码(app.exec_())与gui进行交互。另一种说法是我想要对app.exec_的调用立即返回,就好像gui是无模式的,接下来是与gui进行交互的更多的python代码。



我发现运行PyQt循环的这个示例在一个线程,但不想做一些非常规的事情。有没有办法得到PyQt消息循环来继续处理消息,同时在exec_被调用之后执行主线程中的python代码?

解决方案

最简单的方法是使用IPython:

  ipython --gui = qt4 

请参阅 ipython --help 在线文档获取更多选项(例如gtk,tk等)。


I am testing a gui built using PyQt and I would like the ability to interact with the gui using python code that is executed after the PyQt event loop starts (app.exec_()). Another way of saying this is I would like the call to app.exec_ to return immediately as if the gui were modeless, followed by further python code which interacts with the gui.

I found this example of running the PyQt loop in a thread but don't want to do something so unconventional. Is there any way to get the PyQt message loop to continue processing messages while also executing python code in the main thread after exec_ has been called?

解决方案

The easiest way is to use IPython:

ipython --gui=qt4

See ipython --help or the online documentation for more options (e.g. gtk, tk, etc).

这篇关于从PyQt事件循环中执行Python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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