pygame 鼠标记录多次点击

pygame mouse registering multiple clicks

我有两个列表和一个函数。每次单击鼠标时,该函数都会将一个列表中的项目附加到另一个列表中。但是,鼠标有时会从列表中追加多个项目。仔细研究后,我发现这是因为鼠标按下的时间太长了。无论按住鼠标多长时间,我该怎么做,它只附加一个项目?这是一个代码示例:

list_A = [1,2,3,4,5,6]
list_B = []

def appender():
    if mouse.get_pressed()[0] = 1
        list_B.append(list_A[len(list_A)-1])
        list_A.remove(list_A[len(list_A)-1])

我使用所有正确的设置在游戏循环中调用附加函数。但是,它会在按住鼠标时附加多个项目,有什么建议吗?

我建议使用另一种方法来检测鼠标点击。遍历 pygame 中的 events 并查看其中是否有 MOUSEBUTTONDOWN:

list_A = [1,2,3,4,5,6]
list_B = []
def appender():
    for event in pygame.event.get(): 
        if event.type == pygame.MOUSEBUTTONDOWN:
            list_B.append(list_A[len(list_A)-1])
            list_A.remove(list_A[len(list_A)-1])