Python Forum

Full Version: how to use mouse to locate pixel co-ordinates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to pygame and wouild like to know if it is possible to click on a game surface and find the x,y co-ordinates of the mouxe click. The co-ord system is a bit confusing and I would lkie to be able to plan a drawing by identifying co-ordinates. I seem to recall seeing somewhere the use of a print statement to do this.

Thanks
With pygame events you can do this.
for event in pygame.event.get()
    if event.type == pygame.MOUSEBUTTONDOWN:
        if event.button == 1:
            print(event.pos)
(Aug-09-2022, 10:51 PM)Windspar Wrote: [ -> ]With pygame events you can do this.
for event in pygame.event.get()
    if event.type == pygame.MOUSEBUTTONDOWN:
        if event.button == 1:
            print(event.pos)

Thanks so much for your help Windspar !
Looks like someone is testing their new bot project on us! lol
(Aug-09-2022, 10:51 PM)Windspar Wrote: [ -> ]With pygame events you can do this.
for event in pygame.event.get()
    if event.type == pygame.MOUSEBUTTONDOWN:
        if event.button == 1:
            print(event.pos)

hahaha Windspar - i love your signature !....man that's so funny !