0

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.

2
  • 1
    I couldn't understand why you don't create a new function to include the two functions. What it "because then I would have to change both everytime" means ? Commented Mar 15, 2019 at 8:58
  • you don't gat an error : AttributeError: 'QPushButton' object has no attribute 'triggered'? Commented Mar 15, 2019 at 9:07

2 Answers 2

3

You can connect it like this :

submitButton = QPushButton("Text", self) 
submitButton.clicked.connect(self.submit)
submitButton.clicked.connect(self.clear)
Sign up to request clarification or add additional context in comments.

Comments

0

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.