Full Documentation - https://easy-draw.joemazzone.net/
It's easy! Just download easy_draw.py and include it in your project directory.
Currently, the module is not on PyPI so it is not pip installable. Thus, you must download the easy_draw.py file.
Easy Draw only uses the Python standard library, so there is nothing else to install.
When your program runs, Easy Draw:
- Writes your drawing to an
index.htmlfile in the same folder as your program. - Opens the live drawing in your web browser (http://localhost:8765/).
While your program is running, clicks, mouse movement, and key presses in the browser are sent to your event handlers. Open index.html any time to see your drawing again. Run your program again and the page goes live again.
Close the browser tab (or press Ctrl+C) to stop your program.
To print the finished page's HTML code, use easy_draw.end(print_html=True).
Options for load_canvas():
port- The port for the live drawing. Default is8765.open_browser- Set toFalseif you want to open the page yourself.
- Drawings show in the browser instead of a Tkinter window.
Ovalobjects now rotate properly.Rectanglecan rotate around its top-left corner:rect.rotate(45, from_top_left=True)- Every drawing object shares a
Shapeparent class. - Properties can be changed directly:
circle.radius = 50works likecircle.set_property(radius = 50). Imageobjects can rotate.open_image()works with public image links:easy_draw.open_image("https://example.com/cat.png"). The browser loads the image straight from the link, so viewing the drawing needs an internet connection..rotate()turns every object clockwise, includingArcandText, which used to turn counterclockwise.- Animations made with
time.sleep()loops now show while they run.
EasyDraw.java does the same thing for Java (Java 17 or newer). Download it and put it in the same folder as your program:
public class Main {
public static void main(String[] args) {
EasyDraw.loadCanvas();
EasyDraw.Rectangle square = new EasyDraw.Rectangle(100, 100, 200, 200);
square.setColor("red");
square.eventSetup("<Button-1>", event -> square.rotate(10));
EasyDraw.end();
}
}Compile and run it with javac *.java and java Main.
How it differs from the Python version:
- Shapes are made with
new EasyDraw.ShapeName(...)and the required values in order, likenew EasyDraw.Circle(centerX, centerY, radius). - Optional properties use setters and getters, like
setColor("red"),setColor(255, 0, 0),setBorderWidth(5), andgetRadius(). Coordinates use methods likesetCenter(x, y)andsetXY(x, y). PolygonandLinetake their points as numbers:new EasyDraw.Line(100, 100, 200, 200).- Event handlers are lambdas:
shape.eventSetup("<Button-1>", event -> { ... }). The event strings are the same as Python's. The typed character isevent.character. setDashes(0)andsetBorderColor(null)remove dashes and borders.- Drawing errors throw an
EasyDraw.EasyDrawException. - Files like images and
index.htmluse the folder you run your program from.
The original Tkinter window version is still available as easy_draw_desktop.py. It needs Tkinter and Pillow. Use it with import easy_draw_desktop as easy_draw.
Easy Draw is a easy to use Python module that allows you to create simple graphics primitives (rectangles, circles, polygons, etc.) with just Python function calls.
It is designed to be used with students that only know how to make function calls with Python code.
After learning more about Python (conditionals, iteration, and functions definitions), students can use Easy Draw to make simple animations and games!
Easy Draw is free and open source. If it helps you or your students, you can buy me a coffee ☕
Easy Draw was created by Joe Mazzone, Computer and Software Engineering instructor at William M. Davies, Jr. Career and Technical High School in Lincoln, Rhode Island.
The project was created to introduce Davies' students to GUI development early in an introductory Python course. GUIs are how students interact with software. Let's get them to build GUIs earlier and generate more interest in Computer Science and programming!
Looking for a simple way to create an app with Python? Check out the Easy App project: https://easy-app.joemazzone.net/
For more information about Davies Career and Technical High School, visit https://www.daviestech.org/