Like in topic. I looking for a way to recognize which qpush_button activates the function in this function.
Asked
Active
Viewed 26 times
-2
-
for example I have 3 push_buttons: push_button_1 push_button_2 push_button_3 whole is connect with one function named "how_active" If I press push_button_3 -> how_active return ex. push_button name. – ffg Sep 12 '16 at 18:08
1 Answers
2
There are two ways to do this. One is to include some additional data in the function call via partial functions. The other way is to use the Qt sender() method
self.button1.clicked.connect(lambda: self.button_clicked(self.button1))
self.button2.clicked.connect(lambda: self.button_clicked(self.button2))
def button_clicked(self, button):
print button
The other way is to use the sender()
method
self.button1.clicked.connect(self.button_clicked)
self.button2.clicked.connect(self.button_clicked)
def button_clicked(self):
print self.sender()

Brendan Abel
- 35,343
- 14
- 88
- 118