Created
August 26, 2015 18:28
-
-
Save saleph/59190d095a5ee8facdf2 to your computer and use it in GitHub Desktop.
[qt5] sender() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'tom' | |
import sys | |
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication | |
class Example(QMainWindow): | |
def __init__(self): | |
super().__init__() | |
self.init_ui() | |
def init_ui(self): | |
btn1 = QPushButton("Button 1", self) | |
btn1.move(30, 50) | |
btn2 = QPushButton("Button 2", self) | |
btn2.move(150, 50) | |
btn1.clicked.connect(self.button_clicked) | |
btn2.clicked.connect(self.button_clicked) | |
self.statusBar() | |
self.setGeometry(300, 300, 290, 150) | |
self.setWindowTitle('Event handler') | |
self.show() | |
def button_clicked(self): | |
sender = self.sender() | |
self.statusBar().showMessage(sender.text() + ' was pressed') | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
ex = Example() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment