xxxxxxxxxx
# Simply imports the pygame library
import pygame
import pygame, sys
from pygame.locals import *
def main():
pygame.init()
# Setting the window caption
CAPTION = 'Game'
# Setting the size of the window
(width, height) = (500, 400)
# Adds the window size and caption
DISPLAY = pygame.display.set_mode((width, height))
print("Screen size has been set")
pygame.display.set_caption(CAPTION)
print("Caption has been set")
# Sets some colours
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
# Fills the windows white
DISPLAY.fill(WHITE)
print("Screen has been filled with White")
# Quits the program when the X button is clicked
while True:
for event in pygame.event.get():
if event.type == QUIT:
print("User has quit the program")
pygame.quit()
sys.exit()
pygame.display.update()
main()
xxxxxxxxxx
import pygame # Have to install pygame with 'pip install pygame'
pygame.init() # Initialize pygame
window = pygame.display.set_mode((800, 600)) # Window size
pygame.display.set_caption('Window name')
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT: # If x button on window is pushed
run = False # Exit while loop
window.fill((255, 0, 0)) # Fill window with red
pygame.display.update() # Update the window to show the colour red
pygame.quit() # Quit pygame
xxxxxxxxxx
# Check if you have it installed
pip show pygame
# Check your version of pip (you might need to upgrade)
pip --version
# Install pygame with no cache
pip install pygame --no-cache-dir
# Check if its installed
pip show pygame
# Result:
Name: pygame
Version: 2.1.2
Summary: Python Game Development
Home-page: https://www.pygame.org
Author: A community project.
Author-email: pygame@pygame.org
License: LGPL
Location: c:\users\name\appdata\local\programs\python\python310\lib\site-packages
Requires:
Required-by:
xxxxxxxxxx
import pygame
pygame.init()
WIDTH, HEIGHT = 500, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Hello World!")
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
break
pygame.quit()
xxxxxxxxxx
import pygame
pygame.init()
screen = pygame.display.set_mode(800, 600)
caption = pygame.displayer.set_mode("My gaem")
running = True
while running:
screen.fill(0, 0, 0)
for i in pygame.event.get():
if(i == pygame.quit):
running = False
pygame.quit()
quit()
pygame.update()
xxxxxxxxxx
import pygame
pygame.init()
"""this is how to make a pygame window, the 500,500 is the size of the window
btw(it is your choice what the size is ) """
var = pygame.display.set_mode((500,500))
"""this is how to change the title of the window"""
pygame.display.set_caption('example')
xxxxxxxxxx
import pygame
import sys
pygame.init()
width,height = (600,400)
window = pygame.display.set_mode((width,height)) # this makes the window
pygame.display.set_caption('AnyTitle') #this makes a new title for the window
while True:
for event in pygame.event.get(): #looping through the events in pygame
if event.type == pygame.QUIT: #checking if the user has clicked the close button
pygame.quit() # this quits pygame and closes window
sys.exit() # for smooth closing