每次单击 'Start' 按钮,秒表都会变快

Stopwatch getting faster every click of 'Start' button

from PyQt5 import uic
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication([])
window = uic.loadUi("exercise3.ui")

timer = QTimer()


def start():
    timer.start(10)
    timer.timeout.connect(updateDisplay)


time = 0
def updateDisplay():
    global time
    time += 1
    text = str(time/100)
    window.timeDisplay.setText(text)


def stop():
    timer.stop()


window.startButton.clicked.connect(start)
window.stopButton.clicked.connect(stop)

window.show()
app.exec_()

嗨,超级初学者,不知道为什么,但每次我在 GUI 中按下开始按钮时,秒表似乎变得越来越快,几乎就像间隔在变化一样。不太清楚是怎么回事,如果有人能帮忙,我将不胜感激,谢谢!

我好像解决了! 'timeout.connect()' 调用应该在 start() 槽之外。不知何故,当它在 start() 插槽中时,信号似乎多次连接到同一个插槽,导致插槽也被多次调用,使其每次调用都加速。