This article mainly introduces Python's function of converting the mouse arrow into a graph by using pygame to replace the mouse movement effect. It involves pygame's graphic operations and has some reference value, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:
Think about the school pygame now has a few minutes, and I wrote a small program: picture instead of moving the mouse
Program running effect:
When the mouse moves to the window, the mouse disappears and replaces it with an image .....
The Code is as follows:
# Pygame first programimport pygamefrom pygame. locals import * from sys import exit _ author _ = {'name': 'hongten ', 'mail': 'hongtenzone @ foxmail.com', 'qq': '2016 ', 'version': '1. 0'} BG_IMAGE = 'C: \ test \ 1.gif 'MOUSE _ IMAGE = 'C: \ test \ mouse.gif' pygame. init () # Set the window size screen = pygame. display. set_mode (500,500), 0, 32) pygame. display. set_caption ('hongten \'s First Pygame Program ') bg = pygame. image. load (BG_IMAGE ). convert () mouse_cursor = pygame. image. load (MOUSE_IMAGE ). convert_alpha () while True: for event in pygame. event. get (): if event. type = QUIT: exit () screen. BITs (bg, (0, 0) # x, y coordinate x, y = pygame of the mouse. mouse. get_pos () # Hide the mouse pygame. mouse. set_visible (False) x-= mouse_cursor.get_width ()/2 y-= mouse_cursor.get_height ()/2 # Replace the mouse screen with other images. BITs (mouse_cursor, (x, y) pygame. display. update ()
Click here to download the complete instance code.
I hope this article will help you with Python programming.