如何在 tkinter 中制作计时器?

问题描述:

我想制作一个在创建类的实例时启动的计时器,并在调用方法时停止计时器.有人知道怎么做吗?我搜索了很多教程,但不知道他们在做什么,或者它不适合我的代码.当我使用 self.frame.destroy() 时,它需要忽略计时器代码,这样它就不会被破坏.计时器应包括秒和分钟(如果可能,还应包括毫秒).任何帮助将不胜感激,谢谢.

I want to make a timer that starts when i create an instance of a class, and stop the timer when a method is called. Does anyone know how to make one? I've searched up many tutorials but got no idea what they're doing or it just doesn't fit my code. When i use self.frame.destroy() it needs to ignore the timer code so it doesn't get destroyed. The timer should include second and minutes (and milliseconds if possible). Any help will be greatly appreciated, thanks.

from tkinter import *
root = Tk()

class Start:
    def __init__ (self, master):
        self.master = master
        #code

    def timer(self):
        #start timer
    
    def end(self):
        #end timer

root.mainloop()

编辑:计时器应从 00:00:00 开始,而不是更新时钟.

Edit: The timer should start from 00:00:00 and not an updating clock.

希望这会有所帮助,https://www.geeksforgeeks.org/create-stopwatch-using-python/

它实际上是一个包含小时、分钟和秒的秒表程序,它有三个按钮开始停止重置,分别是功能.

It is actually a stopwatch program which includes hour, minute and second, it has three buttons start, stop and reset with their respective functions.