## 单继承方法,能更好的进行界面与逻辑的分离
# demo4.py
import sys
from PyQt5.QtWidgets import QWidget, QApplication
from referencePackage.pyqt5Demos.ui_FormHello import ui_FormHello
class QmyWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent) # 调用父类构造函数,创建QWidget窗口
self.__ui = ui_FormHello() # 创建UI对象
self.__ui.setupUi(self) # 构造UI界面
self.Lab = "单继承的QmyWidget"
self.__ui.label.setText(self.Lab)
def setBtnText(self, aText):
self.__ui.pushButton.setText(aText)
if __name__ == "__main__":
app = QApplication(sys.argv) # 创建App,用QApplication类
myWidget = QmyWidget()
myWidget.show()
myWidget.setBtnText("间接设置")
sys.exit(app.exec_())
PyQt5_Demo4
最新推荐文章于 2024-09-06 14:57:08 发布