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
#7
(Jul-26-2017, 12:47 PM)Mondaythe1st Wrote: I need to be able to switch the image inside a Def depending on the mouse being press or released.

Then all you need to do is check if the mouse is down. This modification of my example shows the mouse cursor when not held down, and the image when is held down. 

import pygame as pg

screen = pg.display.set_mode((800,600))
screen_rect = screen.get_rect()
done = False
cursor_img = 'curs.jpg'
cursor = pg.image.load(cursor_img).convert()
cursor_rect = cursor.get_rect()
is_cursor = False

while not done:
    screen.fill((255,0,0))
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
    if pg.mouse.get_pressed()[0]:
        is_cursor = True
        pg.mouse.set_visible(False)
    else:
        is_cursor = False
        pg.mouse.set_visible(True)

    cursor_rect.center = pg.mouse.get_pos()
    if is_cursor:
        screen.blit(cursor, cursor_rect)
    pg.display.update()
Recommended Tutorials:
Reply


Messages In This Thread
RE: Problem with pygame not switching the mouse image - by metulburr - Jul-26-2017, 10:53 PM

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