我正在用 python 创建一个程序,我正在使用 pyqt。我目前正在使用 QTimer,我想每秒钟打印一次“计时器工作”并在 5 秒后停止打印。这是我的代码:
timers = []
def thread_func():
print("Thread works")
timer = QtCore.QTimer()
timer.timeout.connect(timer_func)
timer.start(1000)
print(timer.remainingTime())
print(timer.isActive())
timers.append(timer)
def timer_func():
print("Timer works")
Run Code Online (Sandbox Code Playgroud)