Graphical displays with Python and Pygame

Yet More Drawing Functions

The drawAxes, drawHorizontalHash, drawVerticalHash, and drawGrid functions (lines 16-31) use pygame.draw.line to set up the basic graph framework.

By passing the line function the same coordinates for both start and finish, a single pixel dot is rendered. Note that I also could have used to change the size of the grid markers.


In lines 33-37, the drawScale function draws evenly spaced values up the left side of the graph window. Of note here is the self.labelFont.render function, of which self.labelFont was previously defined in the init function.

The render function of a font will create a Pygame surface with the provided text. Once you have a surface, it behaves just like all of the others you've seen so far.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content