import pygame
pygame.init()
a=500
b=500
screen=pygame.display.set_mode((a,b))
run=True
x=250
y=250
while run:
for event in pygame.event.get():
if event.type==pygame.KEYDOWN:
if event.key==pygame.k_w:
y=y-5
if y<=0:
y=b
if event.key==pygame.k_s:
y=y+5
if y>=b:
y=0
if event.key==pygame.k_a:
x=x-5
if x<=0:
x=a
if event.key==pygame.k_d:
x=x+5
if x>=a:
x=0
and this happens when i run the file
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
= RESTART: C:\Users\zagros\Desktop\کد خودم.py
pygame 2.5.2 (SDL 2.28.3, Python 3.12.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\zagros\Desktop\کد خودم.py", line 16, in
if event.key==pygame.k_s:
AttributeError: 'pygame.event.Event' object has no attribute 'key'
import pygame pygame.init() a=500 b=500 screen=pygame.display.set_mode((a,b)) run=True x=250 y=250 while run: for event in pygame.event.get(): if event.type==pygame.KEYDOWN: if event.key==pygame.k_w: y=y-5 if y<=0: y=b if event.key==pygame.k_s: y=y+5 if y>=b: y=0 if event.key==pygame.k_a: x=x-5 if x<=0: x=a if event.key==pygame.k_d:
x=x+5 if x>=a: x=0
and this happens when i run the file Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information.
= RESTART: C:\Users\zagros\Desktop\کد خودم.py pygame 2.5.2 (SDL 2.28.3, Python 3.12.3) Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "C:\Users\zagros\Desktop\کد خودم.py", line 16, in
if event.key==pygame.k_s:
AttributeError: 'pygame.event.Event' object has no attribute 'key'