如何存储多个鼠标点击坐标python

时间:2017-10-04 14:45:12

标签: python-3.x

所以我一直试图找到一种方法来存储多个单击x和y而没有运气,我使用pygame和opencv,但我找不到存储多个x和y的方法而不删除前一组。

import pygame
pygame.init()
while True:
    for e in pygame.event.get():
        if e.type == pygame.MOUSEBUTTONDOWN:
            print (pygame.mouse.get_pos())

1 个答案:

答案 0 :(得分:0)

如果尺寸有限,只需将event.pospygame.mouse.get_pos()附加到列表或collections.deque即可。

import pygame as pg

pg.init()
screen = pg.display.set_mode((640, 480))
clock = pg.time.Clock()

clicks = []
done = False

while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
        elif event.type == pg.MOUSEBUTTONDOWN:
            clicks.append(event.pos)
            print(clicks)

    screen.fill((30, 30, 30))

    pg.display.flip()
    clock.tick(30)

pg.quit()