SoFunction
Updated on 2024-11-15

Examples of pygame module usage in python

This article example describes the python pygame module usage in python, shared for your reference. Specific methods are as follows:

import pygame, sys 
from  import * 
 
#set up pygame 
() 
 
windowSurface = .set_mode((500, 400), 0, 32) 
.set_caption("hello, world") 
 
BLACK = (0, 0, 0) 
WHITE = (255, 255, 255) 
RED = (255, 0, 0) 
GREEN = (0, 255, 0) 
BLUE = (0, 0, 255) 
 
basicFont = (None, 48) 
text = ("Hello ,world", True, WHITE, BLUE) 
textRect = text.get_rect() 
 
 = windowSurface.get_rect().centerx 
 = windowSurface.get_rect().centery 
 
(WHITE) 
 
(windowSurface, GREEN, ((146, 0),  
(291, 106), (236, 277), (56, 277), (0, 106)))  
 
(windowSurface, BLUE, (60, 60), (120,  
60), 4)  
(windowSurface, BLUE, (120, 60), (60,  
120))  
(windowSurface, BLUE, (60, 120), (120,  
120), 4)  
(windowSurface, BLUE, (300, 50), 20, 0) 
 
(windowSurface, RED, (300, 250, 40,  
80), 1)  
 
(windowSurface, RED, ( - 20,  
 - 20,  + 40,  + 40)) 
 
pixArray = (windowSurface)  
pixArray[480][380] = BLACK  
del pixArray  
 
(text, textRect)  
 
() 
 
while True:  
  for event in ():  
    if  == QUIT:  
      ()  
      ()  

The image that is typed after running is as follows:

I hope that what I have described in this article will help you in your Python programming.