Feb-11-2022, 10:25 AM
Has a grid of numbers from 00 - 59 that highlights the background matching the clocks seconds.
import tkinter as tk from time import strftime class Window(tk.Frame): def __init__(self, parent): parent.columnconfigure(0, weight=1) parent.columnconfigure(1, weight=3) text_label = tk.Label(parent, text='Time:') text_label['relief'] = 'groove' text_label.grid(column=0, row=0, sticky='new', padx=2) self.clock = tk.Label(parent) self.clock['relief'] = 'groove' self.clock.grid(column=1, row=0, sticky='new', padx=2) container = tk.Frame() container.grid(column=0, row=1, columnspan=2, sticky='new') for i in range(4): container.grid_columnconfigure(i, weight=3, uniform='images') self.label = [] self.label_text = [i for i in range(60)] col = 0 row = 0 for i in range(60): self.label.append(tk.Label(container, width=3, bg='red', height=2)) self.label[i]['relief'] = 'raised' self.label[i]['borderwidth'] = 1 self.label[i]['text'] = f'{self.label_text[i]:02d}' self.label[i].grid(column=col, row=row, sticky='new', padx=2, pady=2) if col > 4: row += 1 col = 0 else: col += 1 self.update() def update(self): self.clock['text'] = strftime('%I:%M:%S %p') for i in range(60): if self.clock['text'][6:8] in self.label[i]['text']: self.label[i]['bg'] = 'gold' self.label[i]['fg'] = 'black' else: self.label[i]['bg'] = 'black' self.label[i]['fg'] = 'white' self.clock.after(1000, self.update) def main(): root = tk.Tk() root['padx'] = 8 root['pady'] = 4 Window(root) root.mainloop() if __name__ == '__main__': main()