如何在 tkinter 中制作计时器? [英] How to make a timer in tkinter?

查看:61
本文介绍了如何在 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.

这篇关于如何在 tkinter 中制作计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆