Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass

JeffersGlass/pygame_mouse.py Secret

Created Sep 27, 2020
Embed
What would you like to do?
import pygame
import sys #will use the exit function
#Loads all the main pygame modules and initializes them
pygame.init()
clock = pygame.time.Clock()
screen_width=640
screen_height=480
#Sidelength of all of our squares
sideLength = 20
#Create a new Surface with the dimensions listed above
screen=pygame.display.set_mode((screen_width, screen_height))
#Loop forever:
while True:
clock.tick(60)
#The following makes the window close when clicking the "X" or exit button
#Without this, the window will not close, and will need to be killed
#with the task manager
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
#Gives (x,y) tuple of the location mouse was clicked:
clickLocation = pygame.mouse.get_pos()
pygame.draw.circle(screen, (255,255,255), (clickLocation[0], clickLocation[1]), 5)
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment