其他分享
首页 > 其他分享> > PyQt5初探--桌面软件

PyQt5初探--桌面软件

作者:互联网

`

from PyQt5 import QtCore, QtGui, QtWidgets
class Ui(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(739, 581)

    self.centralwidget = QtWidgets.QWidget(MainWindow)
    self.centralwidget.setObjectName("centralwidget")

    self.pushButton = QtWidgets.QPushButton(self.centralwidget)
    self.pushButton.setGeometry(QtCore.QRect(440, 390, 151, 41))
    self.pushButton.setObjectName("pushButton")

    self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
    self.pushButton_2.setGeometry(QtCore.QRect(210, 390, 141, 41))
    self.pushButton_2.setObjectName("pushButton_2")

    self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
    self.lineEdit.setGeometry(QtCore.QRect(270, 160, 291, 41))
    self.lineEdit.setObjectName("lineEdit")

    self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
    self.lineEdit_2.setGeometry(QtCore.QRect(270, 280, 291, 41))
    self.lineEdit_2.setObjectName("lineEdit_2")

    self.label = QtWidgets.QLabel(self.centralwidget)
    self.label.setGeometry(QtCore.QRect(210, 160, 51, 51))
    self.label.setObjectName("label")

    self.label_2 = QtWidgets.QLabel(self.centralwidget)
    self.label_2.setGeometry(QtCore.QRect(221, 274, 41, 61))
    self.label_2.setObjectName("label_2")
    MainWindow.setCentralWidget(self.centralwidget)

    self.menubar = QtWidgets.QMenuBar(MainWindow)
    self.menubar.setGeometry(QtCore.QRect(0, 0, 739, 26))
    self.menubar.setObjectName("menubar")
    MainWindow.setMenuBar(self.menubar)

    self.statusbar = QtWidgets.QStatusBar(MainWindow)
    self.statusbar.setObjectName("statusbar")
    MainWindow.setStatusBar(self.statusbar)

    self.retranslateUi(MainWindow)
    self.pushButton_2.clicked.connect(MainWindow.login) # type: ignore
    self.pushButton.clicked.connect(MainWindow.reg) # type: ignore
    QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "M"))
    self.pushButton.setText(_translate("MainWindow", "注册"))
    self.pushButton_2.setText(_translate("MainWindow", "登录"))
    self.label.setText(_translate("MainWindow", "用户名"))
    self.label_2.setText(_translate("MainWindow", "密码"))

import sys
from PyQt5 import QtCore,QtGui,QtWidgets
from untitled import *

class My(QtWidgets.QMainWindow,Ui):
def init(self):
super(My, self).init()
self.setupUi(self)
self.setupUi2(self)

def login(self):
    pass

def reg(self):
    pass

if name == 'main':
app = QtWidgets.QApplication(sys.argv)
m = My()
m.show()
sys.exit(app.exec())

`
十分简易的pyqt应用
不过做到的逻辑和业务分离
也算是用上了信号和槽

标签:setObjectName,pushButton,--,self,PyQt5,QtWidgets,初探,QtCore,MainWindow
来源: https://www.cnblogs.com/karl-lighting/p/first-gui.html