Python uses pygame to implement image movement instead of mouse movement

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.