Pygame black screen issue [SOLVED]
I am learning python for a week and I get an issue.
So, my pygame window doesn't display any rectangle and doesn't cause any error.
Can you tell me how to fix it?
file name: Screenshot 2020-03-15 at 11.27.51 AM.png
import pygame
import sys
# General setup
pygame.init()
clock = pygame.time.Clock()
# Setting up the main window
screen_width = 1024
screen_height = 768
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Pong')
# Game Rectangles
ball = pygame.Rect(screen_width / 2 - 15, screen_height / 2 - 15, 30, 30)
player = pygame.Rect(screen_width - 30, screen_height / 2 - 70, 10, 140)
opponent = pygame.Rect(30, screen_height / 2 - 70, 10, 140)
bg_color = pygame.Color('grey12')
light_grey = (200, 200, 200)
while True:
# Handling input
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Visuals
screen.fill((255,0,0))
pygame.draw.rect(screen, light_grey, player)
pygame.draw.rect(screen, light_grey, opponent)
pygame.draw.ellipse(screen, light_grey, ball)
pygame.draw.aaline(screen, light_grey, (screen_width/2, 0), (screen_width/2, screen_width))
# Updating the window
pygame.display.flip()
clock.tick(60)
请先登录再写评论。
I just import new pygame
just type this-
at the end of your program not before u typed ur main program .
It did worked for me , and I hope it will work for u too !
hope it helps :>