如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# -*- 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多线程正确的开启姿势详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/shangxiaqiusuo1/article/details/86024590