python基本的信号与槽函数的使用 信号发射 槽函数接收
生活随笔
收集整理的這篇文章主要介紹了
python基本的信号与槽函数的使用 信号发射 槽函数接收
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# 熟悉信號與槽的使用
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys# 創建信號類
class QTypeSigner(QObject):# 定義一個信號sendmsg = pyqtSignal(object)def __init__(self):super(QTypeSigner, self).__init__()def run(self):# 發射信號self.sendmsg.emit("發射信號")# 創建槽類
class QTypeSlot(QObject):def __init__(self):super(QTypeSlot, self).__init__()def get(self, msg):print("QSlot get msg to" + msg)if __name__ == "__main__":send = QTypeSigner()slot = QTypeSlot()# 綁定信號和槽print("綁定信號和槽")send.sendmsg.connect(slot.get)send.run()# 斷開信號和槽print("斷開信號和槽")send.sendmsg.disconnect(slot.get)send.run()
關注公眾號,獲取更多資料
總結
以上是生活随笔為你收集整理的python基本的信号与槽函数的使用 信号发射 槽函数接收的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows MinGW cmake
- 下一篇: 全网最详细 Python如何读取NIFT