There is a plugin I wrote for QGIS and I added some buttons there. From main launch Python script I need to check is specific button is clicked and according to that do some stuff.

I saw a default condition in main script:

def run(self):
    if self.first_start == True:
        self.first_start = False
        self.dlg = frame_builderDialog()
    result = self.dlg.exec_()
    if result:
        'or do something'

In this case I can catch event if I had an "OK\Cancel" button. But I have another simple buttons. I tried to catch them using something like

result_btn = self.dlg.pushButton.clicked

where pushButton is one of the buttons taken from script with dialog, but nothing were returned.

What should be done here?


In python you have "events" and "events handler". when an event occurs they usually (not always...) generate a signal that can be caught by the event handler.

for example :


the event is selectionChanged and the event handler is the function handling the signal received (in that case the handler should be a function (written by you) called test (or any other naming ofc).

your snippet :

result_btn = self.dlg.pushButton.clicked

Is meaningless (imho ...)

So ... in your case u should try an


And write an my_event_handler function of course.


You could connect the pushButton to a function so that when it is clicked, it will do something:

result_btn = self.dlg.pushButton.clicked.connect(self.someFunction)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.