4. PyQt5-实现显示和业务逻辑分离
Posted leo1875
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4. PyQt5-实现显示和业务逻辑分离相关的知识,希望对你有一定的参考价值。
- Author: Notus([email protected])
- Create: 2019-02-10
- Update: 2019-02-10
PyQt5 实现显示和业务逻辑分离, 继承主界面文件的主窗口类
环境
操作系统: Windows 10 专业版 64-bit (10.0, Build 16299) (16299.rs3_release.170928-1534)
Python Version: 3.7.1
PyQt5 Version: 5.11.3
Qt Designer Version: 5.11.2
界面代码如下(firstMainWin.py)
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file ‘firstMainWin.ui‘
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(220, 160, 141, 51))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "haha"))
self.pushButton.setText(_translate("MainWindow", "PushPush"))
主要逻辑代码如下
‘‘‘
PyQt5 实现显示和业务逻辑分离, 继承主界面文件的主窗口类
@Author: Notus([email protected])
@Create: 2019-02-10
@Update: 2019-02-10
‘‘‘
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from firstMainWin import *
class MyMainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWin = MyMainWindow()
myWin.show()
sys.exit(app.exec_())
运行后显示效果如下图
以上是关于4. PyQt5-实现显示和业务逻辑分离的主要内容,如果未能解决你的问题,请参考以下文章