Search code examples
qtpyqtpysideqpushbutton

PySide : How to get the clicked QPushButton object in the QPushButton clicked slot?


I am new to PySide. I want to get the QPushButton obj (such as use it to get its text) in its clicked slot.

button = QtGui.QPushButton("start go")
button.clicked.connect(self.buttonClick)

def buttonClick(self):
    ... # How can I get the button  object?
    # print button.text()  how to get the text : 'start go' ?

Thanks!


Solution

  • Here is what I did to solve the problem:

    button = QtGui.QPushButton("start go")
    button.clicked.connect(lambda: self.buttonClick(button))
    
    def buttonClick(self, button):
        print button.text()