- 1 year ago
"Maximize" pygame window
Comment
1 / 1
To maximize a Pygame window, you can use the pygame.display.set_mode()
function to set the display mode to the maximum screen resolution available. Here's an example:
pythonimport pygame
# Initialize Pygame
pygame.init()
# Get the maximum screen resolution
screen_info = pygame.display.Info()
screen_width, screen_height = screen_info.current_w, screen_info.current_h
# Set the display mode to the maximum screen resolution
screen = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
# Main loop
while True:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
# Draw on the screen
screen.fill((255, 255, 255))
pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(0, 0, 100, 100))
# Update the screen
pygame.display.update()
In this example, we use the pygame.display.Info()
function to get the maximum screen resolution available and then pass it to the pygame.display.set_mode()
function with the pygame.FULLSCREEN
flag to set the display mode to fullscreen. We then draw a red rectangle on the screen and update the display in a main loop. To exit the program, we handle the pygame.QUIT
event and call pygame.quit()
and exit()
to exit Pygame and the program.