0

like the title say's I do not know why my code hate's it when the screen is touched.

import pygame, time, keyboard

screen=pygame.display.set_mode((300, 300))
UpOrDown = 0
Y = 75

def backGround():
    pygame.draw.rect(screen, (0,255,255), (0, 0, 300, 200))
    pygame.draw.rect(screen, (0,255,0), (0, 200, 300, 100))

def ball():
        pygame.draw.circle(screen, (255,0,0),
                       [150, Y], 30, 0)

while screen == True:
    while keyboard.is_pressed('u'):
        backGround()
        ball()
        pygame.display.flip()
        time.sleep(.1)
        print(Y)

        if UpOrDown == 0:
            Y += 10
            if Y == 225:
                UpOrDown = 1

        elif UpOrDown == 1:
            Y -= 10
            if Y == 75:
                UpOrDown = 0

    Y = 225
    UpOrDown = 1
    ball()

If you could can you alter it or tell me why it doesn't work

Window crashing when it is opened

Mint
  • 1
  • 1
  • General advice: Use booleans for binary flags, not 0/1. – Barmar Jan 24 '23 at 17:39
  • If you're getting an error message, please include it in the question. – John Gordon Jan 24 '23 at 17:46
  • 1
    You have to handle the events. See [Pygame Window not Responding after few seconds](https://stackoverflow.com/questions/64830453/pygame-window-not-responding-after-few-seconds). Also see [How can I make a sprite move when key is held down](https://stackoverflow.com/questions/9961563/how-can-i-make-a-sprite-move-when-key-is-held-down). – Rabbid76 Jan 24 '23 at 17:47

0 Answers0