Answers for "pygame window inside a function"

2

how to create a window in pygame

import pygame
pygame.init() #initialize pygame
SCREEN_WIDTH = 600 # width (in px)
SCREEN_HEIGHT = 800 # height (in px)

WIN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) # creates a screen of 600px X 800px

while True:
	pygame.display.update() # updates the screen
Posted by: Guest on July-02-2020
-1

how to make a window in pygame

import pygame
pygame.init()
screen = pygame.display.set_mode((700, 500))
pygame.display.set_caption('Prototype_1')
carryOn = True
while carryOn:
	for event in pygame.events.get():
		if event.type == pygame.QUIT:  # If user clicked close
        	CarryOn = False  # Flag that we are done so we exit this loop
            print("we should be closing now!")
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_x:  # Pressing the x Key will quit the game
                CarryOn = False
            print("we should be closing now")

pygame.quit()
Posted by: Guest on January-03-2022

Python Answers by Framework

Browse Popular Code Answers by Language