Examples of Pygame module usages in Python

Source: Internet
Author: User
The examples in this paper describe the usage of pygame modules in Python and share them for your reference. Here's how:

Import Pygame, sys from pygame.locals import * #set up Pygame pygame.init () Windowsurface = Pygame.display.set_mode ((500 , (+), 0, +) pygame.display.set_caption ("Hello, World") BLACK = (0, 0, 0) White = (255, 255, 255) RED = (255, 0, 0) GRE EN = (0, 255, 0) BLUE = (0, 0, 255) Basicfont = Pygame.font.SysFont (None), Text = Basicfont.render ("Hello, World", Tru E, White, BLUE) Textrect = Text.get_rect () Textrect.centerx = Windowsurface.get_rect (). CenterX textrect.centery = WindowS Urface.get_rect (). CenterY Windowsurface.fill (White) Pygame.draw.polygon (Windowsurface, GREEN, (146, 0), (291, 106), ( 236, 277), (277), (0, 106)) Pygame.draw.line (Windowsurface, BLUE, (), (+), 4) pygame.draw.line (window Surface, Blue, (+), (+)) Pygame.draw.line (Windowsurface, Blue, (+), (+), 4) PYGAME.DRAW.CIRCL E (Windowsurface, BLUE, (), 0) pygame.draw.ellipse (windowsurface, RED, (), 1) pygame.draw.re CT (Windowsurface, RED, (tExtrect.left-20, textrect.top-20, Textrect.width +, Textrect.height +)) Pixarray = Pygame. PixelArray (windowsurface) pixarray[480][380] = BLACK del pixarray windowsurface.blit (text, textrect) Pygame.display. Update () While True:for event in Pygame.event.get (): if Event.type = = QUIT:pygame.quit () sys.exit   ()

After the operation, the following images are typed:

Hopefully this article will help you with Python programming.

  • 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.