May-14-2020, 03:33 PM
I'm trying my luck with a clock
Just can't seem to get it to update.
I've tried with the both the after method and while loops.
It would appear that I'm not putting it in the right place in the code or I need to make a new function and call it.
Any help would be great. Thanks
Just can't seem to get it to update.
I've tried with the both the after method and while loops.
It would appear that I'm not putting it in the right place in the code or I need to make a new function and call it.
Any help would be great. Thanks
# /usr/bin/env python3 import os import tkinter as tk from tkinter import ttk from datetime import datetime class AlarmClock: def __init__(self, master): self.master = master self.master.columnconfigure(0, weight=1) self.master.rowconfigure(0, weight=1) style = ttk.Style() style.configure('Clock.TFrame', background='slategray') self.clock_frame = ttk.Frame(self.master, style='Clock.TFrame', border=8) self.clock_frame.grid(column=0, row=0, sticky='new') self.clock_frame.grid_columnconfigure(0, weight=3) now = datetime.now() time_string = now.strftime('%H:%M:%S') self.show_time = tk.StringVar() self.show_time.set(time_string) self.clock() def clock(self): clock_nums = ttk.Style() clock_nums.configure('Clock.TLabel', background='black', foreground='red', anchor='n', \ font=('sans', 18, 'bold'), relief='ridge', padding=8) self.label = ttk.Label(self.clock_frame, text=self.show_time.get(), style='Clock.TLabel') self.label.grid(column=0, row=0, sticky='new') self.label.grid_columnconfigure(0, weight=3) def main(): root = tk.Tk() root.title('Alarm Clock') root.geometry('400x200+50+50') AlarmClock(root) root.mainloop() if __name__ == '__main__': main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts