Member-only story
Learn Python By Making Animated Clock With Graphics.PY Library
This tutorial is a chapter from Python Grammar (my book) which you can Get PDF (with 7 books for price of 1) or Buy it on Amazon.
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…