Python-based Pygame implement a picture instead of a mouse move effect

Source: Internet
Author: User
The examples in this article describe Python-based pygame implementation of a picture instead of a mouse move effect. Share to everyone for your reference, as follows:

Think of the school pygame now a few minutes, wrote a small program: pictures instead of mouse movement

The operation effect of the program:

When the mouse moves to the window, the mouse is gone, instead of the picture .....

The code section is as follows:

#pygame First Programimport pygamefrom pygame.locals import *from sys import exit__author__ = {' name ': ' Hongten ',       ' ma Il ': ' hongtenzone@foxmail.com ',       ' QQ '  : ' 648719819 ',       ' Version ': ' 1.0 '}bg_image = ' c:\\test\\1.gif ' Mouse_ IMAGE = ' c:\\test\\mouse.gif ' pygame.init () #设置窗口的大小screen = Pygame.display.set_mode ((500, 500), 0, 32) Pygame.display.set_caption (' hongten\ ' 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.blit (BG, (0, 0))  #鼠标的x, y coordinate  x, y = Pygame.mouse.get_pos ()  #隐藏鼠标  Pygame.mouse.set_visible (False)  x-= Mouse_cursor.get_width ()/2  y-= Mouse_cursor.get_height ()/2  # Use other graphics instead  of mouse screen.blit (Mouse_cursor, (x, y))  pygame.display.update ()

Full instance code code click here to download this site.

I hope this article is helpful for Python program design.

  • Related Article

    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.