[英]PyQt Window not displaying on screen
I am a beginner learning PyQt and the following code is not displaying any window on the screen, though I can see that the build is successful.我是学习 PyQt 的初学者,下面的代码没有在屏幕上显示任何窗口,但我可以看到构建成功。 I'm not able to recognize the mistake, could you help me please?
我无法识别错误,你能帮我吗?
#!/usr/bin/python
import sys
from PyQt4 import QtGui
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
app.exec_()
if __name__ == '__main__':
main()
Try to add sys.exit(app.exec_())
at the end of main()
function. 尝试在
main()
函数的末尾添加sys.exit(app.exec_())
。
This worked for me (I use python3): 这对我有用(我使用python3):
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
frame = QtGui.QMainWindow()
frame.setGeometry(50, 50, 600, 400)
frame.setWindowTitle('FrameTitle')
frame.show()
sys.exit(app.exec_())
Try to use the following: 尝试使用以下内容:
window = QMainWindow()
window.setWindowTitle('PictureWorkshop');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.