Python Forum
[PyGame] how to use mouse to locate pixel co-ordinates
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] how to use mouse to locate pixel co-ordinates
#1
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
Reply
#2
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)
99 percent of computer problems exists between chair and keyboard.
Reply
#3
(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 !
Reply
#4
Looks like someone is testing their new bot project on us! lol
Reply
#5
(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 !
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020