我对Qt相当陌生。我使用 Gtk3 和 Glade UI 设计器在 python 中构建了一些东西,包括构建我的代码以作为事件发生时运行的函数运行。在 GTK 中,如果主循环当前没有循环,您的 UI 将冻结。
现在,我正在尝试学习 PyQt。看起来很奇怪的是,我告诉 Window 显示,UI 出现,Python 提示返回。但是 GUI 并没有像我对 GTK 所期望的那样冻结(因为我没有运行主循环)。
就从 python 解释器测试 UI 内容而言,这非常好。但这怎么可能?Qt 是否正在制作另一个正在循环的线程或其他什么?
这是代码:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_multippp(object):
def setupUi(self, multippp):
multippp.setObjectName(_fromUtf8("multippp"))
multippp.resize(371, 43)
self.verticalLayout = QtGui.QVBoxLayout(multippp)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.label = QtGui.QLabel(multippp)
self.label.setObjectName(_fromUtf8("label"))
self.verticalLayout.addWidget(self.label)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout.addLayout(self.verticalLayout_2)
self.retranslateUi(multippp)
QtCore.QMetaObject.connectSlotsByName(multippp)
def retranslateUi(self, multippp):
multippp.setWindowTitle(QtGui.QApplication.translate("multippp", "Multiple PPP Accounts", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("multippp", "More than one PPP account found, please select one:", None, QtGui.QApplication.UnicodeUTF8))
import sys
app = QtGui.QApplication(sys.argv)
multippp = QtGui.QDialog()
ui = Ui_multippp()
ui.setupUi(multippp)
multippp.show()
# At this point the python prompt returns, but the UI is interactive. I can add/remove buttons at the python prompt.