Steps
These steps need to be followed to draw a digital clock using Turtle in Python:
- Import all the modules( time, datetime, turtle).
- Then, Create two turtles, one for making a rectangular box and another for showing the current time.
- Now, Create a window and set the background color using bgcolor() function of the window to orange.
- Set the turtle's position, create a rectangle, and then hide the turtle.
- After that, try to obtain our system's current time (hour, minute, second). Then, we will use our datetime module for this.
- Now, Use our other turtle object to show the current time.
Now let's look at the code to draw a digital clock using Turtle in Python.
Code
# Python program to draw digital clock using Turtle
import time
import datetime as dte
import turtle
# Create a turtle to display time
t1 = turtle.Turtle()
# Create a turtle to create rectangle box
t2 = turtle.Turtle()
# Create screen
screen = turtle.Screen()
# Set background color of the screen
screen.bgcolor("orange")
# Obtain current hour, minute and second from the system
sec = dte.datetime.now().second
min = dte.datetime.now().minute
hr = dte.datetime.now().hour
t2.pensize(3)
t2.color('black')
t2.penup()
# Set the position of turtle
t2.goto(-20, 0)
t2.pendown()
# Create rectangular box
for i in range(2):
t2.forward(200)
t2.left(90)
t2.forward(70)
t2.left(90)
# Hide the turtle
t2.hideturtle()
while True:
t1.hideturtle()
t1.clear()
# Display the time
t1.write(str(hr).zfill(2)
+ ":"+str(min).zfill(2)+":"
+ str(sec).zfill(2),
font=("Arial Narrow", 35, "bold"))
time.sleep(1)
sec += 1
if sec == 60:
sec = 0
min += 1
if min == 60:
min = 0
hr += 1
if hr == 13:
hr = 1

You can also try this code with Online Python Compiler
Run Code
Check out this article - Quicksort Python
Output

You can compile it with online python compiler.
You can also read about Palindrome Number in Python here.
Frequently Asked Questions
What are the steps used to plot using Turtle?
The steps to plot a turtle program are as follows:
Step 1: Import the turtle module.
Step 2: Create a turtle to control.
Step 3: Draw shapes using the turtle methods.
Step 4: Run turtle.done() function.
How to create a new turtle object?
The Turtle() method creates and returns a new turtle object in Python.
What are the attributes of the turtle library?
A location, an orientation (or direction), and a pen are the three attributes of the turtle. Color, width, and on/off state are all pen attributes (also called down and up). "Move forward 10 spaces" and "turn left 90 degrees" are commands that the turtle responds to based on its current location.
Is it possible to combine turtle and Tkinter?
Yes. Python turtle has two modes of operation: standalone and embedded into a bigger Tkinter program. When utilizing turtle embedded, you work with RawTurtle, TurtleScreen, and optionally ScrolledCanvas instead of Turtle and Screen. As desired, you create your Tkinter interface containing your turtle graphics on a Canvas.
In Python, how can you move a turtle without drawing?
Toggle drawing on and off with up and down, or move without drawing with the "setx", "sety", or "goto" functions.
Conclusion
In this article, we have extensively discussed how to draw a digital clock using Turtle in Python, along with the steps and code.
We hope that this blog has helped you enhance your knowledge of how to draw a digital clock using Turtle in Python. If you would like to learn more, check out our article Panda Using Turtle, Star using Turtle In Python, Chess Board using Turtle. Do upvote our blog to help other ninjas grow. Happy Coding!