【问题标题】:How can I make the datetime display as integers(second)___python如何使日期时间显示为整数(秒)___python
【发布时间】:2021-04-05 00:55:55
【问题描述】:

我想做一个定时器, 但显示为 0:00:00.000000 如何更改显示为 0:00:00

import time, datetime
import tkinter as tk
import time, datetime



win = tk.Tk()
win.geometry('200x100+550+250')
win.title('Timer')
win.config(bg='#323232')
win.attributes('-topmos', 1)

start = datetime.datetime.now()

frame = tk.Frame()

lab = tk.Label(text='', bg='#000000', fg='#FFFFFF')
lab.pack()


def update():
    dur = datetime.datetime.now() - start
    lab.config(text=dur)
    frame.after(20, update)

开始按钮:当点击按钮开始计时

St_button = tk.Button(text='Start', command=update)
St_button.pack()

frame.mainloop()

【问题讨论】:

标签: python datetime time


【解决方案1】:

显而易见且简单的方法是

    lab.config(text=str(dur)[:7])

【讨论】:

    猜你喜欢
    • 2016-11-02
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 2016-09-23
    相关资源
    最近更新 更多