[英]How do I run a Python Qt file in Ubuntu?
Here's the sample code that I want to run: 这是我要运行的示例代码:
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.setGeometry(0, 0, 500, 300)
window.setWindowTitle("Dummy PyQt file")
window.show()
The file is saved as sample.py
. 该文件另存为
sample.py
。 The following command isn't working: 以下命令不起作用:
$ python ./sample.py
You need to call app.exec_()
to start the Qt
event loop . 您需要调用
app.exec_()
来启动Qt
事件循环 。 Without it the program exits immediately before anything can be shown on screen. 没有它,程序将立即退出,然后屏幕上将无法显示任何内容。
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. 初始化小部件并在主窗口上调用
show()
,需要通过调用app.exec_()
启动Qt事件循环。
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.setGeometry(0, 0, 500, 300)
window.setWindowTitle("Dummy PyQt file")
window.show()
app.exec_()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.