Pyqt object-oriented template creation

Use ide as pycharm

1. Code

from  PyQt5.Qt import *

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("pyqt")
        self.resize(500,500)
        self.setup_ui()
        
	#setup_ui是建立不同的对象,更加清楚
    def setup_ui(self):
        $code$   
          
        #$code$是让模板生效后光标默认停留的位置
        #code是变量名可以自己修改,位置也可以自己修改

#用于测试,如果不用可以删除
if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    windwos=Window()
    windwos.show()
    sys.exit(app.exec_())

pycharm settings

1. Enter settings

Insert picture description here

2. Enter the event template

Search live will appear complete

Insert picture description here

3. Create a template

(1) Click python, then click the + sign
Insert picture description here
(2) add
Insert picture description here
(3) to take effect,
Insert picture description here
click define, then select python
Insert picture description here
and then click apply, then click ok to take effect
Insert picture description here

4. Show

Insert picture description here
Enter the table key to take effect
Insert picture description here

Guess you like

Origin blog.csdn.net/tansty_zh/article/details/108332092