-2

Like in topic. I looking for a way to recognize which qpush_button activates the function in this function.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
ffg
  • 13
  • 1
  • 5
  • 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 Answers1

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