Digital clock is running based on system time. But after 10 seconds it stops.
Before this you can even see that the last 'tick' is 2 seconds instead of 1 second. That means it slows down somehow. Why does it happen?
from tkinter import *
from tkinter import ttk
from time import strftime
import datetime
root = Tk()
root.title('Clock')
tabs = ttk.Notebook(root)
tabs.pack()
clock_tab = ttk.Frame(tabs)
timer_tab = ttk.Frame(tabs)
stopwatch_tab = ttk.Frame(tabs)
alarm_tab = ttk.Frame(tabs)
international_time_tab = ttk.Frame(tabs)
tabs.add(clock_tab, text='Clock')
tabs.add(timer_tab, text='Timer')
tabs.add(stopwatch_tab, text='Stopwatch')
tabs.add(alarm_tab, text='Alarm')
tabs.add(international_time_tab, text='International time')
def time():
time_str = datetime.datetime.now().strftime("%H:%M:%S")
date_str = datetime.datetime.now().strftime("%d.%m.%Y")
time_label.config(text = time_str)
time_label.after(1000, time)
date_label.config(text = date_str)
date_label.after(1000, time)
time_label = Label(root,font = ('calibri', 20))
time_label.pack()
date_label = Label(root,font = ('calibri', 15))
date_label.pack()
exit_btn = ttk.Button(
root,
text = 'Exit',
command = lambda: root.quit()
)
exit_btn.pack(fill = 'x')
def exit_func(event):
root.quit()
root.bind('<Return>', exit_func)
time()
mainloop()
CodePudding user response:
Add this root.mainloop
. Btw, when I typed time period, I didn't get any intellisense
. There is no intellisense
. But I can see intellisense
in my example.
import sys
from tkinter import *
import time
def timing():
current_time = time.strftime("%H : %M : %S")
clock.config(text=current_time)
clock.after(200,timing)
root=Tk()
root.geometry("600x300")
clock=Label(root,font=("times",60,"bold"),bg="blue")
clock.grid(row=2,column=2,pady=25,padx=100)
timing()
root.mainloop()