I'm trying to learn mouse events with PyGame, and I'm trying to draw a box wherever the user clicks. I'm setting a variable equal to pygame.mouse.get_pos(), and calling individual tuple members according to the mouse's x, y position. Here's the code:
import pygame, sys
pygame.init()
screen = pygame.display.set_mode((800, 600))
mousepos = pygame.mouse.get_pos()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.draw.rect(mousepos[0], mousepos[1], 20, 20)
The game starts up, but when I click, it crashes, giving this error:
Traceback (most recent call last):
File "C:\Users\User\Documents\proj\Python\mouse.py", line 13, in <module>
pygame.draw.rect(mousepos[0], mousepos[1], 20, 20)
TypeError: must be pygame.Surface, not int
I know what I'm doing wrong: my parameters for draw.rect()
are of invalid types, but I don't know how to change the parameters so they're appropriate. So how do I fix this?