Module 6 - Section 0 - Repeat!

6.0.3 - Using the mouse

To get the position of the mouse inside a graphics screen created with pygame we use the command,

pos = pygame.mouse.get_pos()

inside the main loop, so depending of the clock.tick() command the position is read constantly.

The variable pos is a tuple of two numbers that we can use to move a shape using the tuples numbers as coordinates. The commands are:

x = pos[0] # assign the x position of the mouse to variable x
y = pos[1] # assign the y position of the mouse to variable y

and to draw a shape at the position x,y :

pygame.draw.circle(screen, RED, [ x,  y], 30, 0)