1

I have been trying to get started with pygame and I was following a tutorial that I found on youtube in order to do so. However, pygame does not seem to want to render anything. So far I am just trying to move a rectangle around with arrow keys (code will follow).

import pygame

# initialize pygame
pygame.init()


# create the screen
win = pygame.display.set_mode((500,500))

# Set the caption
pygame.display.set_caption("My First Game")

x = 50
y = 50
width = 40
height = 60
velocity = 5

run = True
while run:
    pygame.time.delay(100)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
        x-=velocity
    if keys[pygame.K_RIGHT]:
        x+= velocity
    if keys[pygame.K_UP]:
        y-= velocity
    if keys[pygame.K_DOWN]:
        y+=velocity




    pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
    pygame.display.update()


pygame.quit()

I have done some research and I believe the "fix" for this issue with pygame on Mac is to use python 3.6. In order to do that, I would need to run a virtual environment. In summary how would I run a virtual environment for python 3.6?

jbeachy
  • 21
  • 1
  • 6
  • Use something like Pycharm in which you can select the Python interpreter. It will create a Virtual environment for you when you create a new project. https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html – SriTeja Chilakamarri Apr 17 '20 at 07:46

0 Answers0