基本了解了pyqt的原理,到下载安装好qt后,桌面上会出现Qt Designer。
我们可以利用它进行界面的设计,然后保存为一个后缀为.ui的文件,我们需要把它转化为后缀为.py的文件。
进入cmd,进入后缀为.ui的文件目录,命令 pyuic4 -o dome.py dome.ui
这样我们就可以得到我们需要的文件了:
打开.py,就可以看到转换得到的python代码,就可以添加动作了。
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'dome.ui'## Created: Thu Jul 25 13:25:12 2013# by: PyQt4 UI code generator 4.10.2## WARNING! All changes made in this file will be lost!from PyQt4 import QtCore, QtGuitry: _fromUtf8 = QtCore.QString.fromUtf8except AttributeError: def _fromUtf8(s): return stry: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding)except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig)class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(400, 300) self.buttonBox = QtGui.QDialogButtonBox(Dialog) self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32)) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) self.buttonBox.setObjectName(_fromUtf8("buttonBox")) self.retranslateUi(Dialog) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))