对pyqt5多线程正确的开启姿势详解
程序员文章站
2023-12-16 19:22:22
如下所示:
# -*- coding: utf-8 -*-
import sys
from pyqt5.qtcore import qthread, p...
如下所示:
# -*- coding: utf-8 -*- import sys from pyqt5.qtcore import qthread, pyqtsignal from pyqt5.qtwidgets import qapplication, qmainwindow, qwidget, qmessagebox, \ qpushbutton, qlineedit, qlabel, qtooltip, qcombobox, qtextedit class mybeautifulclass(qmainwindow): def __init__(self): super(mybeautifulclass, self).__init__() self.init_ui() def init_ui(self): self.resize(1000, 800) self.setwindowtitle('demo of pyqt5 qthread') self.btn_1 = qpushbutton('start', self) self.btn_1.setgeometry(100, 100, 100, 50) self.btn_1.clicked.connect(self.slot_btn_1) self.linedit_2 = qlineedit(self) self.linedit_2.setgeometry(100, 400, 300, 50) def slot_btn_1(self): self.mbt = mybeautifulthread() self.mbt.trigger.connect(self.slot_thread) self.mbt.start() def say_love(self): print('say love') def slot_thread(self, msg_1, msg_2): self.linedit_2.settext(msg_1 + msg_2) class mybeautifulthread(qthread): trigger = pyqtsignal(str, str) def __init__(self): super(mybeautifulthread, self).__init__() def run(self): w = mybeautifulclass() w.say_love() self.trigger.emit('lo', 've') def main(): app = qapplication(sys.argv) w = mybeautifulclass() w.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
以上这篇对pyqt5多线程正确的开启姿势详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。