Create digital clock using Python-Turtle Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Turtle is a special feature of Python. Using Turtle, we can easily draw on a drawing board. First, we import the turtle module. Then create a window, next we create a turtle object and using the turtle methods we can draw in the drawing board. Prerequisites: Turtle Programming in Python Installation: To install this module type the below command in the terminal. pip install turtle Note: To create a clock we will use the 'time' and 'DateTime' modules of Python also, To install time use the following command: Below is the implementation. Python3 import time import datetime as dt import turtle # create a turtle to display time t = turtle.Turtle() # create a turtle to create rectangle box t1 = turtle.Turtle() # create screen s = turtle.Screen() # set background color of the screen s.bgcolor("green") # obtain current hour, minute and second # from the system sec = dt.datetime.now().second min = dt.datetime.now().minute hr = dt.datetime.now().hour t1.pensize(3) t1.color('black') t1.penup() # set the position of turtle t1.goto(-20, 0) t1.pendown() # create rectangular box for i in range(2): t1.forward(200) t1.left(90) t1.forward(70) t1.left(90) # hide the turtle t1.hideturtle() while True: t.hideturtle() t.clear() # display the time t.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 Output: Code Explanation: The code starts by creating two turtles.The first turtle, t1, will be used to create a rectangular box on the screen.The second turtle, t2, will be used to display the time.The code then sets up some variables.The hour variable stores the current hour as a number (e.g., 13).The minute variable stores the current minute as a number (e.g., 59).And the second variable stores the current second as a number (e.g., 2).Next, the code obtains information about the system time from datetime object dt.datetime.now().second .This object contains information about the date and time that is currently being displayed on your computer or device.The next section of code sets up some variables for drawing onscreen using turtle graphics objects.These variables store information about how wide and high each line should be drawn in pixels (i.e., they are called pensize() variables), and they also specify which color to use for each line (i.e., they are called color() variables).Finally, these variables tell the turtle to start drawing at position (-20, 0) in the upper-left corner of the screen and to stop drawing. The code first creates two turtles, one to display time and another to create a rectangular box.Next, the code sets up the screen and obtains the current hour, minute, and second from the system.The code then sets the position of the turtle for each line in the for a loop.The first line moves the turtle 200 pixels to the right, 90 pixels down and 70 pixels forward.The next line moves the turtle again but this time it left 90 pixels to the right and moved it 70 pixels down.The last two lines move the turtle forward by 200 pixels again and left it at its original position.Next, the code hides both turtles and waits for a second.Once a second has passed, it displays time by writing. Comment More infoAdvertise with us R romy421kumari Follow Improve Article Tags : Python Python-turtle Practice Tags : python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 6 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 6 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like