PyQt4 窗口在运行程序时不出现,但在 ipython 上出现 [英] PyQt4 window does not appears while running the program but appears on ipython

查看:33
本文介绍了PyQt4 窗口在运行程序时不出现,但在 ipython 上出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试用 PyQt4.并尝试了此代码.

I was trying out PyQt4. and tried this code.

import sys                                                                    
from PyQt4 import QtGui                                                       

app = QtGui.QApplication(sys.argv)                                            
window = QtGui.QWidget()                                                      
window.show()  
print 'end'

当我在 ipython 上尝试时,上面的代码有效,但当我将它们写入文件并运行时却无效.我还尝试通过 chmod +x 更改权限.代码实际运行(我在最后添加了打印语句以确认代码是否运行到最后的原因),我没有得到一个窗口.

This above code works when i try it on on ipython, But it doesn’t when i write them into a file and run it. I also tried changing the permission by chmod +x. The code actually runs(the reason i added a print statement at the end to confirm if the code is running till the end), i don’t get a window.

我在 ubuntu 14.04 上运行 python 2.7.6

im running python 2.7.6 on ubuntu 14.04

推荐答案

初始化小部件并调用 后,您需要通过调用 app.exec_() 来启动 Qt 事件循环show() 在您的主窗口上.

You need to start the Qt event loop by calling app.exec_() once you have initialised the widgets and called show() on your main window.

这篇关于PyQt4 窗口在运行程序时不出现,但在 ipython 上出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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