Skip to content
← Back to Community
[SOLVED] [pygame] Updating mouse positions
Profile icon
ETHANSIAO
I've been attempting to create a simple program which prints the x and y coordinates of my mouse. However, the program repeatedly prints the same x and y position. What am I doing wrong?

Here's my repl: https://repl.it/@ETHANSIAO/Mouse-Positions
(Please ignore the commented code, I plan on saving that for another project.)

Edit: not sure why the text is being displayed as if it's a program, sorry about that!

Edit 2: just put in the correct link, sorry about that!

Answered by Joshua_AnthonyA [earned 5 cycles]
View Answer
Voters
Profile icon
PAULX
Profile icon
ETHANSIAO
Comments
hotnewtop
Profile icon
Joshua_AnthonyA

repl not found

Profile icon
ETHANSIAO

@Joshua_AnthonyA just updated it, sorry about that!

Profile icon
Joshua_AnthonyA

@ETHANSIAO I don't know why but this worked for me:

for event in pygame.event.get(): position = pygame.mouse.get_pos() print(position)
Profile icon
ETHANSIAO

@Joshua_AnthonyA Works for me too, thank you so much!

Profile icon
JosephCoppin1

Had this problem too, and I think that you just need to call pygame.event.get() every time you want the curser position to update, so you can just say:

pygame.event.get()
position = pygame.mouse.get_pos()
print(position)

and then it will keep giving back the old position even when you aren't moving the curser.

Profile icon
ETHANSIAO

@JosephCoppin1 hey man i know it's been 3 years but i had the same problem just now, lol. thanks!