You must do the following to get started with Pygame:
import pygame
This opens a window of size 640,480, and stores it in a variable called screen.
Setting up a name for the pygame window requires the following syntax:
pygame.display.set_caption('Name')
Changes you make to the screen—e.g. filling it with color, or drawing on it, do not show up immediately!
So how to do it?
You have to call this function:
pygame.display.update()
The coloring in pygame works on RGB mode.
The code for coloring is:
color_Name = (r,g,b)
To draw lines
pygame.draw.lines(screen, color, closed, pointlist, thickness)
To draw rectangle
pygame.draw.rect(screen, color, (x,y,width,height), thickness)
To draw circle
pygame.draw.circle(screen, color, (x,y), radius, thickness)
To make a loop use the following code:
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
import pygame
background_colour = (255,255,255) # White color
(width, height) = (300, 200) # Screen size
color=(0,0,0) #For retangle
screen = pygame.display.set_mode((width, height)) #Setting Screen
pygame.display.set_caption('Drawing') #Window Name
screen.fill(background_colour)#Fills white to screen
pygame.draw.rect(screen, color, (100,50,30,40), 1) #Drawing the rectangle
pygame.display.update()
#Loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()