In my first project, we had developed a digital clock using Python. It is a very simple project that bring to me good insights and some hours about libraries, strings, and other ideas for future projects.
Feel free to copy the code below and to leave some comments to help us to improve our studies and codes.
We had the below result:
CODE:
+------------------------------------------------+
| import tkinter as tk |
| from time import strftime |
| |
| # Create the main window |
| root = tk.Tk() |
| root.title("Clock") |
| |
| # Define the function to update the time |
| def time(): |
| string = strftime('%H:%M:%S %p') |
| label.config(text=string) |
| label.after(1000, time) |
| |
| # Create the clock label |
| label = tk.Label(root, font=('calibri', 40, |
| 'bold'), background='black', foreground='white')|
| label.pack(anchor='center') |
| |
| # Call the time function to update the clock |
| time() |
| |
| # Run the main loop |
| root.mainloop() |
+------------------------------------------------+



