Here I, have am tying to simply make 2 rectangles using pygame module. I have made them using 2 methods but they don't seem to work. Please suggest some that could work. (I am using Python 3.8.3)
Here is the code:
import pygame
pygame.init()
screen = pygame.display.set_mode((100, 100))
box_color = (255, 0, 0)
color = (0, 150, 100)
ybox = 20
xbox = 20
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
ybox += 5
if (ybox >= 45):
ybox = 45
pygame.draw.rect(screen, box_color, pygame.Rect(xbox, ybox, 50, 50), 2)
pygame.display.flip()
pygame.draw.rect(screen, box_color, pygame.Rect(20, 95, 50, 50), 2)
pygame.display.flip()
screen.fill(color)
pygame.display.update()