运行qtdesigner.exe
构建界面转化为python
pyuic5 -o SexyManTmp.py SexyMan.ui
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'SexyMan.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(-60, 130, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.retranslateUi(Dialog)
'''注册确定按钮的点击事件'''
self.buttonBox.accepted.connect(Dialog.accept)
'''注册取消按钮的点击事件'''
self.buttonBox.rejected.connect(self.on_click)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
'''确定按钮的点击事件'''
def on_click(self):
print("PyQt5 button click 2")
class MyWindow(QMainWindow, Ui_Dialog):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.setupUi(self)
'''取消按钮的点击事件'''
def accept(self):
print("PyQt5 button click 1")
if __name__ == '__main__':
app = QApplication(sys.argv)
myWin = MyWindow()
myWin.show()
sys.exit(app.exec_())