Answer the question
In order to leave comments, you need to log in
How can I quickly change the text of a Label (Tkinter) (Datetime)?
I make electronic watches. I made the Label variable and in text = (date_time.hour, minute, second)
so that they are always updated wrote:
while True:
TimeHour = Label(root, text=date_time.hour, width=5, height=2,font=(' Verdana', 16, 'bold'))
TimeMinute = Label(root, text=date_time.minute, width=5, height=2,font=('Verdana', 16, 'bold')
TimeSecond = Label(root, width =5, text=date_time.second, height=2,font=('Verdana', 16, 'bold')
Why doesn't it work, can you tell me how to make this infinite timer?
Answer the question
In order to leave comments, you need to log in
Everything is terribly simple:
from tkinter import *
from tkinter.ttk import *
from datetime import *
root = Tk()
timeVar = StringVar()#Это переменная для надписи
Label(root,textvar=timeVar, font=('Verdana', 16, 'bold')).pack()
def update():
timeVar.set(datetime.now().strftime("%H:%M:%S"))
root.after(1000, update)#тут добавляем вызов через 1000мс из mainloop
update()#вызываем первый раз
root.mainloop()#это аналог while True
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question