<> One preface
After the previous one QT Introductory articles , Readers should be QT There's a simple concept , This article is about separating windows from business logic , Reduce coupling ;
Knowledge seeker (Inheriting the spirit of open source, Spreading technology knowledge;)
<> Two Separate code
*
First of all, use the idea of object-oriented , inherit QWidget, If multiple components , Multiple inheritance can be used ;
def __init__(self, parent=None): super().__init__(parent)
*
Next, define number initialization gui Content of , take gui Method into the constructor to initialize ;
*
At last _main_ Call in , It realizes the separation of interface and business logic
# -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QApplication,
QWidgetfrom PyQt5.QtGui import QIcon """ With window icon """ class Windos(QWidget): def
__init__(self): # Inherit parent method super().__init__() # initialization gui self.init_gui() def
init_gui(self): # Set the location and size of the pop-up window , amount to move + resize self.setGeometry(500, 500, 250,
300) # Set title self.setWindowTitle(' Knowledge seeker ') # Set window icon self.setWindowIcon(QIcon(
'zszxz.png')) # display self.show() if __name__ == '__main__': # Basic module app =
QApplication(sys.argv) # Call object ex = Windos() # Loop exit sys.exit(app.exec_())
The display is as follows , The mainstream is single inheritance
Technology
Daily Recommendation