测试代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ui-a.ui'
#
# Created: Wed Jun 12 17:14:40 2019
# by: PyQt4 UI code generator 4.9.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_firstMainWindow(object):
def setupUi(self, firstMainWindow):
firstMainWindow.setObjectName(_fromUtf8("firstMainWindow"))
firstMainWindow.resize(556, 444)
firstMainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.centralwidget = QtGui.QWidget(firstMainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.queren = QtGui.QPushButton(self.centralwidget)
self.queren.setGeometry(QtCore.QRect(430, 360, 93, 28))
self.queren.setObjectName(_fromUtf8("queren"))
firstMainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(firstMainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 556, 23))
self.menubar.setObjectName(_fromUtf8("menubar"))
firstMainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(firstMainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
firstMainWindow.setStatusBar(self.statusbar)
self.retranslateUi(firstMainWindow)
QtCore.QMetaObject.connectSlotsByName(firstMainWindow)
def retranslateUi(self, firstMainWindow):
firstMainWindow.setWindowTitle(QtGui.QApplication.translate("firstMainWindow", "UI设计师", None, QtGui.QApplication.UnicodeUTF8))
self.queren.setText(QtGui.QApplication.translate("firstMainWindow", "确认", None, QtGui.QApplication.UnicodeUTF8))
if __name__=="__main__":
import sys
reload(sys) #
sys.setdefaultencoding( "utf-8" ) # 这两步是为了解决print中文报ascii编码错误
app=QtGui.QApplication(sys.argv)
widget= QtGui.QMainWindow()
ui= Ui_firstMainWindow()
ui.setupUi(widget)
widget.show()
sys.exit(app.exec_())
结果: