DEV Community

Wulfi
Wulfi

Posted on

5 2

Create a Clock using Python

You can create a simple Clock using Python and in this post we use tkinter to create the GUI for our clock. Firstly download the fonts from the link here and install it in your system if you want to have the same font like in this post.

Now that you've installed the fonts, copy the following code and save it in your system. Try to run the code and your Clock will be displayed.

from tkinter import * 
from tkinter.ttk import *

from time import strftime 

root = Tk()
root.title("Clock")

def time():
    string = strftime("%H:%M:%S %p")
    label.config(text=string)
    label.after(1000, time)

label = Label(root, font=("ds-digital", 50), background="black", foreground="cyan")
label.pack(anchor="center")
time()

mainloop()
Enter fullscreen mode Exit fullscreen mode

The clock is shown below:
Image description

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay