Sometimes it is convenient to know which widget is the sender of a signal. For this, PyQt5 has the sender() method.
有时知道哪个组件是信号的发送者是很方便的.为此,PyQt5有sender()方法.
下面是源码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/10/23 下午1:43
# @Author : Aries
# @Site :
# @File : 1023-01-Event sender.py
# @Software: PyCharm
import sys
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
class Exp(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
btn1 = QPushButton('按钮1',self)
btn1.move(30,50)
btn2 = QPushButton('按钮2',self)
btn2.move(150,50)
btn1.clicked.connect(self.buttonClicked)
btn2.clicked.connect(self.buttonClicked)
self.statusBar()
self.setGeomet