Reputation:
I have Gui with Pyqt5. I have a few QLineEdit in my Gui, and when you click the button it submits the value of those variables. It's working fine. I also have a function which clears all the LineEdits. It's working fine too.
But I want that when I press Submit the variables get submitted and then cleared. Can I run a function in another function without writing it new (because then I would have to change both everytime).
My button is like this:
submitButton = QPushButton("Text", self)
submitButton.triggered.connect(self.submit)
To achieve this can I just do it like that?
submitButton = QPushButton("Text", self)
submitButton.triggered.connect(self.submit, self.clear)
PS: If there is a typo in my code don't worry cause my code in general is fine. I just wrote it down on my phone.
Upvotes: 0
Views: 97
Reputation: 159
I would, instead of making one button call 2 methods make this button call 1 method that does 2 things.
def do_thing(button):
button.submit()
button.clear()
submitButton = QPushButton("Text", self)
submitButton.triggered.connect(do_thing(self))
Upvotes: 0
Reputation: 7206
You can connect it like this :
submitButton = QPushButton("Text", self)
submitButton.clicked.connect(self.submit)
submitButton.clicked.connect(self.clear)
Upvotes: 3