對pyqt5多線程正確的開啟姿勢詳解
更新時間:2019年06月14日 21:05:19 作者:coding上下求索
今天小編就為大家分享一篇對pyqt5多線程正確的開啟姿勢詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
# -*- 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多線程正確的開啟姿勢詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python實現(xiàn)對excel表中的某列數(shù)據(jù)進行排序的代碼示例
這篇文章主要給大家介紹了如何使用python實現(xiàn)對excel表中的某列數(shù)據(jù)進行排序,文中有相關(guān)的代碼示例供大家參考,具有一定的參考價值,需要的朋友可以參考下2023-11-11
Python 實現(xiàn)數(shù)據(jù)庫(SQL)更新腳本的生成方法
當我們需要準備更新腳本的使用,不小心會忘記改動了哪里,所以小編試著用Python來實現(xiàn)自動的生成更新腳本,具體操作方法,大家參考下本文吧2017-07-07

