Python Forum
Problem with pygame not switching the mouse image
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with pygame not switching the mouse image
#3
I mimicked this. If you look in the comments you can see I reworked the first example.
I set this at the very top
pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0)) ##invisible mouseColorblack = (0,0,0)

From what you're saying I should do something like
WnY=pygame.image.load('whitenyellow.png').convert_alpha()
WnR=pygame.image.load('whitenred.png').convert_alpha()

outside of my mouse function, then

def mouse():
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN:
            print("mouse down")
            mouse_cursor=WnY
            return
        elif event.type == pygame.MOUSEBUTTONUP:
            print("mouse up")
            mouse_cursor=WnR
            return

to avoid reloading the images constantly.*
Is there a good way to read the mouse consistently and fast and accurate?

I've also tried
        global b1
        ex = pygame.mouse.get_pressed(0)
        if ex == (1, 0, 0)  and b1 == False:
            b1 = True
            print("mouse down")
            mouse_cursor=pygame.image.load('whitenyellow.png').convert_alpha()
            print(ex) 
b1 is used to keep track if the mouse has switched images yet. I dont know if python/pygame works like this, but I figured once the image is set to be the "mouse" it sticks. So there's no reason to keep setting it 60x a second. With b1, once it's set to True, it's set and the if statement should skip it next time it's read. Right?
Reply


Messages In This Thread
RE: Problem with pygame not switching the mouse image - by Mondaythe1st - Jul-26-2017, 04:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue with GUI screen switching in Python QT5 code greenelephant 1 293 Apr-04-2024, 09:58 PM
Last Post: deanhystad
  Switching from tkinter to gtk is difficult! snakes 1 1,491 Aug-08-2022, 10:35 PM
Last Post: woooee
  [Tkinter] canvas image problem DPaul 4 6,552 Nov-24-2021, 07:06 AM
Last Post: DPaul
  Problem about image and button scotesse 5 3,027 Apr-27-2020, 10:09 AM
Last Post: scotesse
  [Tkinter] Unable to Access global Variable when switching between frames tziyong 1 3,513 Nov-03-2019, 01:08 AM
Last Post: balenaucigasa
  [Tkinter] Call a function when switching layouts 4096 0 3,564 Sep-22-2019, 07:39 PM
Last Post: 4096
  [PyGUI] Switching between two frames using Tkinter jenkins43 1 4,656 Jul-17-2019, 10:53 AM
Last Post: metulburr
  [Tkinter] switching frames nick123 2 7,970 Apr-18-2019, 04:50 PM
Last Post: francisco_neves2020
  [Tkinter] Problem loading an image from directory into a Canvas object tiotony 3 3,893 Sep-02-2018, 06:47 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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