Back to Tutorials


Note: Visit our Get Started page for more information about installing MediaLib.

This tutorial was designed for Computer Science Students.

All of the examples in this tutorial can be downloaded from the Gallery.

Learning Objectives

We are going to learn:

  1. How to use the function defined by other's library.
  2. Some void functions defined in MediaLib.

Introduction to MediaLib

Download MediaLib and the MediaLib Exercise 1 files from the Gallery.

Practice using MediaLib

Run the program in ex1.py. You will see a new window with a black background and two eyes displayed (which are eye.png and eye2.png in the same folder).

In the text output, you will see Click the left button on the mouse to continue. Left click in the window and you will see the eyes change their positions.

Click again and the eyes will move again. Click again and the window will disappear.

Have a look and understand the program in ex1.py

  • import
    • is for using a library, code written by someone else. Here we want import medialib.py so we can use the commands in that program, to draw on screen (for example).
  • draw
    • given the name of an image file, and 2 numbers (X and Y coordinates), draws the image at that position. The top-left corner of the image will be at point (x,y).
  • Coordinate System
  • wait_mouse_leftclick()
    • blocks the program until the user presses the left mouse button.
  • clear
    • Clears the drawing window. The default background color is black.
  • all_done
    • Don’t forget to have this command at the of all your programs that use the medialib. This command closes the graphic window.

See the documentation for more detailed information.


Modify the program in ex1.py as you like and run it to see what will happen:

  • Change the coordinates in draw() function
  • Change the image file in draw() function (put the image file into the folder of ex1.py if you want to load your own image)
  • Change the background color in clear() function
  • Draw more images by using more draw() functions
  • Move the images to more places by using the combination of clear(), draw() and wait_mouse_leftclick() functions.

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.