Python Brython Extras

This article includes information on setting timers, using event handlers, and drawing shapes in Brython.

Sara Jenis avatar
Written by Sara Jenis
Updated over a week ago
Free banner

We have created some programs with examples of how to set timers, use event handlers, and draw shapes in our Bryton editor. All teachers and students can fork a copy of the programs to try out the code!

If you would like to add this into existing assignments, you can create a custom assignment! You can also fork the program to your sandbox and assign it to your class from there.

Timers

This program shows how to call a function on a delay using timer.set_timeout and timer.set_interval . You can check out the program here.


Gif showing timer

This program shows how to create a "click to pause" timer in Brython. You can check out the code here.


Gif showing click to pause timer

Event Handlers

X and Y coordinate on mouseMove

This code will allow you to track mouse movement event method similar to mouseMoveMethod() in JavaScript Graphics. You can check out the code here.


Gif showing event handler for mouse movement


Removing Handlers

This program shows how to remove event handlers after an event.

Gif showing event handler for mouse movement and graphical output

Click Image for Effect

Click image for effect will add images to a canvas and do different things based on which image the user clicks in CSP / Brython. You can check out the code here.

Gif showing click image for effect


Lines and Shapes in Brython

Lines at Angles

This program will show you how to draw a line in Brython and use a formula in a function to set the angles. You can check out the code here.

Shapes

This program will show you how to draw an ellipse, circle, ranuculoid, and fill in or outline them. You can check out the code here.


Still have questions? Contact our team at hello@codehs.com to learn more!

Did this answer your question?