首页 > 解决方案 > pygame " event " object has no attribute "pos"

问题描述

if event.type == pygame.FINGERDOWN:
    touch_pos = event.pos

When I run this code ,I get the error 'Event' object has no attribute 'pos' .

If I use pygame.MOUSEBUTTONDOWN it works fine ,with no error.

How to solve this ,do you need to import something?

标签: pythonpygame

解决方案


According to this table from https://www.pygame.org/docs/ref/event.html, FINGER~ events have an x and y attribute instead of a pos attribute.

AUDIODEVICEREMOVED which, iscapture
FINGERMOTION       touch_id, finger_id, x, y, dx, dy
FINGERDOWN         touch_id, finger_id, x, y, dx, dy
FINGERUP           touch_id, finger_id, x, y, dx, dy
MOUSEWHEEL         which, flipped, x, y
MULTIGESTURE       touch_id, x, y, pinched, rotated, num_fingers
TEXTEDITING        text, start, length
TEXTINPUT          text
WINDOWEVENT        event

推荐阅读