Digital Clock

date
Aug 29, 2023
slug
digital-clock
status
Published
tags
Python
summary
This code in Python displays the current time in a digital format.
type
Post
Import modules:
  • tkinter
    • The tkinter module is used to create graphical interfaces.
    • The ttk module is used to create graphical interfaces.
  • time
    • The time module is used to obtain the time.
    • The strftime module is used to format the time.
We configure the graphical interface:
  • Tk(): Create the main window.
  • title(): Sets the title of the window.
  • resizable(): Makes the window not resizable.
  • iconbitmap(): Sets the window icon.
We define the function to display the time:
  • strftime: Formats the current time to a specific string.
  • config: Configures the Label widget text.
  • after: Schedule the time to update every second.
We configure the Label widget:
  • font: Set the text font, sizes and style.
  • background: Sets the background color of the widget.
  • foreground: Set the text color.
We start the application:
  • time(): Call the function to display the time.
  • mainloop(): Starts the main loop of the graphical interface.

Full Code