Using graphics.py to draw a clock in Python

Member-only story

Learn Python By Making Animated Clock With Graphics.PY Library

Ghost Together
7 min readMay 14, 2022

--

You will need basic knowledge of graphics.py library and it’s installed.

You need to know how to run basic python.py scripts.

In this tutorial we will draw basic shapes in a window to make a clock.

We will also animate clock’s arrow using delay method.

First let’s import graphics.py, initialize window and draw clock body:

# Import graphics.py library and math
from graphics import *
import math
# Open the blank window for drawing
window = GraphWin("Draw A Clock",
640,
480,
autoflush=False)

Note addition of autoflush=False passed as last parameter to GraphWin object. This enables smooth animation when update() method is called.

Without it animation will still work but flicker.

(We’ll see this in just a moment.)

# Define the clock center
cx = 200
cy = 150
# Define length of minute bars around the…

--

--

Ghost Together
Ghost Together

Written by Ghost Together

Ghost Together @ https://semicolon.dev is an alternative to Twitter. Sign up to meet other makers of things.

No responses yet