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.