Drawing a rectangle in Python using the Pygame library is essential for many game development tasks. In this question, we'll explore the specific steps involved in drawing a rectangle for Python 3.2.
In the provided Python code:
<code class="python">import pygame, sys from pygame.locals import * def main(): pygame.init() DISPLAY = pygame.display.set_mode((500, 400), 0, 32) WHITE = (255, 255, 255) BLUE = (0, 0, 255) DISPLAY.fill(WHITE) pygame.draw.rect(DISPLAY, BLUE, (200, 150, 100, 50)) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() if __name__ == "__main__": main()</code>
This code demonstrates how to draw a simple blue rectangle in a Pygame window. For more information and tutorials on using Pygame, refer to the Pygame website: www.pygame.org.
The above is the detailed content of How do I draw a rectangle in a Pygame window using Python?. For more information, please follow other related articles on the PHP Chinese website!