我有这个 PySide 应用程序,我想每 1 秒运行一次函数 pp,但是当我运行该应用程序时,它只运行了 1 次。
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())
控制台输出:
LOL
True
我在 Qt documentation 中搜索但什么也没发现
最佳答案
您的连接错误。将 self.timer.timeout.connect(self.pp())
更改为 self.timer.timeout.connect(self.pp)
,因为您想要连接到函数,而不是其输出。
关于python - PySide6 中 QTimer() 函数的问题该函数不循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70118356/