# Create a window to display the demo.
时间: 2023-12-14 11:35:39 浏览: 76
Sure, here's a simple example code in Python using the Pygame library to create a window:
```
import pygame
# Initialize Pygame
pygame.init()
# Set the width and height of the window
size = [800, 600]
screen = pygame.display.set_mode(size)
# Set the title of the window
pygame.display.set_caption("Demo Window")
# Set the background color
background_color = (255, 255, 255)
# Main loop
done = False
while not done:
# Check for events
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Fill the background color
screen.fill(background_color)
# Update the display
pygame.display.flip()
# Quit Pygame
pygame.quit()
```
This code creates a window with a white background color and sets the title to "Demo Window". The while loop keeps the window open until the user clicks the close button. Inside the loop, we fill the window with the background color and update the display.
阅读全文