Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to create a windows in pygame

# 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()
Source by www.petercollingridge.co.uk #
 
PREVIOUS NEXT
Tagged: #create #windows #pygame
ADD COMMENT
Topic
Name
1+8 =