Display

class ev3dev2.display.Display(desc='Display')

Bases: ev3dev2.display.FbMem

A convenience wrapper for the FbMem class. Provides drawing functions from the python imaging library (PIL).

xres

Horizontal screen resolution

yres

Vertical screen resolution

shape

Dimensions of the screen.

draw

Returns a handle to PIL.ImageDraw.Draw class associated with the screen.

Example:

screen.draw.rectangle((10,10,60,20), fill='black')
image

Returns a handle to PIL.Image class that is backing the screen. This can be accessed for blitting images to the screen.

Example:

screen.image.paste(picture, (0, 0))
clear()

Clears the screen

update()

Applies pending changes to the screen. Nothing will be drawn on the screen until this function is called.

line(clear_screen=True, x1=10, y1=10, x2=50, y2=50, line_color='black', width=1)

Draw a line from (x1, y1) to (x2, y2)

circle(clear_screen=True, x=50, y=50, radius=40, fill_color='black', outline_color='black')

Draw a circle of ‘radius’ centered at (x, y)

rectangle(clear_screen=True, x1=10, y1=10, x2=80, y2=40, fill_color='black', outline_color='black')

Draw a rectangle where the top left corner is at (x1, y1) and the bottom right corner is at (x2, y2)

point(clear_screen=True, x=10, y=10, point_color='black')

Draw a single pixel at (x, y)

text_pixels(text, clear_screen=True, x=0, y=0, text_color='black', font=None)

Display text starting at pixel (x, y).

The EV3 display is 178x128 pixels

  • (0, 0) would be the top left corner of the display
  • (89, 64) would be right in the middle of the display

text_color : PIL says it supports “common HTML color names”. There are 140 HTML color names listed here that are supported by all modern browsers. This is probably a good list to start with. https://www.w3schools.com/colors/colors_names.asp

font : can be any font displayed here
http://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/display.html#bitmap-fonts
  • If font is a string, it is the name of a font to be loaded.
  • If font is a Font object, returned from ev3dev2.fonts.load(), then it is used directly. This is desirable for faster display times.
text_grid(text, clear_screen=True, x=0, y=0, text_color='black', font=None)

Display text starting at grid (x, y)

The EV3 display can be broken down in a grid that is 22 columns wide and 12 rows tall. Each column is 8 pixels wide and each row is 10 pixels tall.

text_color : PIL says it supports “common HTML color names”. There are 140 HTML color names listed here that are supported by all modern browsers. This is probably a good list to start with. https://www.w3schools.com/colors/colors_names.asp

font : can be any font displayed here
http://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/display.html#bitmap-fonts
  • If font is a string, it is the name of a font to be loaded.
  • If font is a Font object, returned from ev3dev2.fonts.load(), then it is used directly. This is desirable for faster display times.

Bitmap fonts

The ev3dev2.display.Display class allows to write text on the LCD using python imaging library (PIL) interface (see description of the text() method here). The ev3dev2.fonts module contains bitmap fonts in PIL format that should look good on a tiny EV3 screen:

import ev3dev2.fonts as fonts
display.draw.text((10,10), 'Hello World!', font=fonts.load('luBS14'))
ev3dev2.fonts.available()

Returns list of available font names.

ev3dev2.fonts.load(name)

Loads the font specified by name and returns it as an instance of PIL.ImageFont class.

The following image lists all available fonts. The grid lines correspond to EV3 screen size:

_images/fonts.png