GUVI
Back

events not found 

Created 2 years ago
74 Views
0 Comments
Lithikesh
@Lithikesh
Lithikesh
@LithikeshProfile is locked. Login

even though I typed the code which I given below with correct syntax it is showing the error Traceback (most recent call last):

File "C:\Users\LLK\Desktop\pygame course by Lk\main 2.py", line 18, in <module>

for event in events :

NameError: name 'events' is not defined

what can i do did I did any mistake

import pygame, sys
from pygame.locals import *

catx = 10
caty = 10
screen = 10


def myquit():
    pygame.quit()
    sys.exit()


def check_inputs(events):
    global catx, caty, screen


for event in events :
    if event.type == QUIT:
        pygame.quit()
    else:
        if event.key == KEYDOWN:
            if event.key == K_ESCAPE:
                myquit()
            if event.key == K_RIGHT:
                catx += 5
                print("move rect right")
            if event.key == K_LEFT:
                catx -= 5
                print("move rect left")
            else:
                print(event.key)
screen.fill((0,0,0))
pygame.draw.rect(screen,(255, 255, 255),(catx,50,50,10))
pygame.display.update()

def main():
    global screen
    pygame.init()
    window = pygame.display.set_mode((1000, 200))
    pygame.display.set_caption("trench")
    screen = pygame.display.get_surface()
    pygame.display.update()
while True:
     check_inputs(pygame.events.get())

Comments
Please login to comment.
 
Powered by habitate.io Habitate