2

I have this PySide app and I want to run the function pp every 1 second, but when I run the app it only ran for 1 time.

import sys from PySide6.QtWidgets import QMainWindow, QApplication from PySide6 import QTimer class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) ### self.timer = QTimer() self.timer.timeout.connect(self.pp()) self.timer.start(1000) print(self.timer.isActive()) def pp(self): print("LOL") if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() #app.show() sys.exit(app.exec()) 

The console outputs:

LOL True 

I searched in the Qt documentation but found nothing

1
  • TYPO: change to self.timer.timeout.connect(self.pp) Commented Nov 26, 2021 at 0:06

1 Answer 1

7

Your connection is wrong. Change self.timer.timeout.connect(self.pp()) to self.timer.timeout.connect(self.pp), because you want to connect to the function, not its output.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, I totally missed that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.