How I can prevent the user from pressing the button several times in a row in PYQT5

Asked

Viewed 100 times

1

[Solved]I’m pretty beginner in pyqt, mainly in python, I’m with a problem I looked at several foruns, how can I prevent the user from pressing the button multiple times in a row? I already tried using disable() and then enable again, tried to disconnect and then connect, even tried to use Hide(), but as my function scrolls in the same thread as the function ends it exceeded the "clickadas" I did during that time, I saw on the internet that I would have to make another thread for my function and in the main receive the disabled clickadas, but as I said I am very beginner in python and could not find anything specific, if someone could send me some material, or have another solution to my problem, I would appreciate it. my code:

self.botler_1.clicked.connect(lambda: self.sendData("$LM1"))
def sendData(self, text):
        print("Sending data")
        print(text)
        
  • You can try using disable to disable the button after clicking

  • does not work, because the events of clciks were waiting for the buttons to be enabled again

  • Because you do not create a variable to count clicks and if it is bigger than 1 you ignore the click?

1 answer

0


[Solved]It doesn’t work kkk , because as it is rolling in the same thread the clickadas I did while the event was happening are waiting for the boot to be enabled again, what I’m trying to do now and create another thread to enable it again, but I’m having trouble with Finish Because I created the botoesclickados method, that when I click it will enter this function will start my thread and as soon as it ends will enable again but it does not send me the finished sign def botoesclickados(self):

    self.send = sendDataThread()
        self.send.start()
        self.botler_1.setEnabled(False)
        self.send.finished.connect(lambda: self.libera)
    
    def libera(self):
        self.botler_1.setEnabled(True)

class sendDataThread(QThread):
    def run(self):
        for x in range (5):
            print(x)
            time.sleep(1)

EDIT: I managed to get the lambda off the line self.send.finished.connect(lambda: self.libera) self.send.finished.connect(self.libera)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.