pygame mouse

How to get the mouse position in pygame

We can get the mouse position with pygame.mouse.get_pos() import pygame,sys from pygame.locals import* pygame.init() screen=pygame.display.set_mode((400,400)) game_running=True while game_running: for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() mouse_position=pygame.mouse.get_pos() print(mouse_position) pygame.display.update() Copy Run this code and hover your mouse on the pygame window. This will print mouse position. We can me this interesting by moving a rectangle […]