PyQt4 window does not appears while running the pr

2019-02-21 02:54发布

问题:

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'

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.

im running python 2.7.6 on ubuntu 14.04

回答1:

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.



标签: python pyqt4