Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make a pygame window

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')
Comment

pygame window

import pygame
pygame.init()

SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('game')
clock = pygame.time.Clock()

#colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
            screen.fill(BLACK)
            
            
    pygame.display.update()
    clock.tick(60)
    
    
pygame.quit()
quit()
Comment

Make a basic pygame window

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
Comment

pygame window

# import the pygame module, so you can use it
import pygame
 
# define a main function
def main():
     
    # initialize the pygame module
    pygame.init()
    # load and set the logo
    logo = pygame.image.load("logo32x32.png")
    pygame.display.set_icon(logo)
    pygame.display.set_caption("minimal program")
     
    # create a surface on screen that has the size of 240 x 180
    screen = pygame.display.set_mode((240,180))
     
    # define a variable to control the main loop
    running = True
     
    # main loop
    while running:
        # event handling, gets all event from the event queue
        for event in pygame.event.get():
            # only do something if the event is of type QUIT
            if event.type == pygame.QUIT:
                # change the value to False, to exit the main loop
                running = False
     
     
# run the main function only if this module is executed as the main script
# (if you import this as a module then nothing is executed)
if __name__=="__main__":
    # call the main function
    main()
Comment

pygame make a window

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()
Comment

pygame window

import pygame
    background_colour = (255,255,255)
    (width, height) = (300, 200)
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption('Tutorial 1')
    screen.fill(background_colour)
    pygame.display.flip()
    running = True
    while running:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          running = False
Comment

how to write something in the pygame window

import pygame
pygame.init()
print("Sussy Baka!")
Comment

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()
Comment

how to create a window in pygame

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
 
Comment

how to make window pygame

import pygame

pygame.init()

win = pygame.display.set_mode((800,600))
pygame.display.set_caption('A bit Racey')
win.fill(255,255,255)
Comment

PREVIOUS NEXT
Code Example
Python :: how to find the summation of all the values in a tuple python 
Python :: waitkey in python 
Python :: remove last element in list python 
Python :: pandas extracting tables from pdf 
Python :: how to create a matrix from list in python 
Python :: how to get function help in jupyter notebook 
Python :: beautifulsoup find element containing text 
Python :: appdata/local/microsoft/windowsapps/python: permission denied 
Python :: duck typing in python 
Python :: pyglet on button press 
Python :: python stack size 
Python :: code a gui 
Python :: img_sm = pygame.transform.scale(img, (32, 32)) 
Python :: len 
Python :: In is_lodes_form( : Missing id-axis pairings. 
Python :: change group box title font size 
Python :: The current Numpy installation fails to pass a sanity check due to a bug in the windows runtime. 
Python :: Highlighting the shortest path in a Networkx graph 
Shell :: get cpu frequency linux 
Shell :: amazon linux 2 install stress 
Shell :: git allow unrelated histories 
Shell :: how to remove node_modules from git 
Shell :: react router v5 install 
Shell :: download teamviewer for ubuntu using terminal 
Shell :: install snap on kalicannot communicate with server: Post "http://localhost/v2/snaps/core": dial unix /run/snapd.socket: connect: no such file or directory 
Shell :: cmd clear dns cache 
Shell :: nginx stop commands 
Shell :: list file size as mb 
Shell :: how to get my ip address mac terminal 
Shell :: kazam install ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =