import pygame # set up pygame pygame.init() # Set up the screen screen = pygame.display.set_mode((500,400)) pygame.display.set_caption('Hello World') # set up colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) # set up fonts basicFont = pygame.font.SysFont(None, 48) # set up the text text = basicFont.render('Hello world!', True, WHITE, BLUE) textRect = text.get_rect() textRect.centerx = screen.get_rect().centerx textRect.centery = screen.get_rect().centery # draw white background on screen screen.fill(WHITE) # draw a green polygon on screen pygame.draw.polygon(screen, GREEN, ((146, 0), (200, 100), (230, 150), (159, 230), (56, 277), (0, 106))) # draw some blue lines onto the surface pygame.draw.line(screen, BLUE, (60,60), (120,120), 4) pygame.draw.line(screen, BLUE, (120,60), (60,120)) pygame.draw.line(screen, BLUE, (0,0), (100,100), 4) # get a red circle on the screen pygame.draw.circle(screen, RED, (300,50), 20, 0) # green ellipse somewhere pygame.draw.ellipse(screen, GREEN, (300, 250, 40, 80)) # draw text background rectangle onto screen pygame.draw.rect(screen, RED, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height+40)) # get a pixel array of the screen pixArray = pygame.PixelArray(screen) pixArray[480][380] = BLACK del pixArray # draw the text onto the screen screen.blit(text, textRect) # draw the window onto the screen pygame.display.update() # run the game loop running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEMOTION: x, y = event.pos print(f'Mouse at {x}, {y}') pygame.quit()