Python:如何检测鼠标点击图像的时间?

时间:2022-11-03 19:58:11

Lately I have been working with pygame and I was trying to detect when a mouse clicks over an image. Here is some code that I had but I kept getting a error saying: 'pygame.Rect' object has no attribute 'collide_point'. How do I fix the code? Here is the code that I used:

最近我一直在使用pygame,我试图检测鼠标何时点击图像。这是我的一些代码,但我不断收到错误说:'pygame.Rect'对象没有属性'collide_point'。我该如何修复代码?这是我使用的代码:

if event.type == pygame.MOUSEBUTTONDOWN:  
    (x, y) = event.pos  
    if Button_Start.get_rect().collide_point(x, y):  
        print()  

1 个解决方案

#1


The attribute is collidepoint(). There's no underscore.

属性是collidepoint()。没有下划线。

if event.type == pygame.MOUSEBUTTONDOWN:  
    (x, y) = event.pos  
    if Button_Start.get_rect().collidepoint(x, y):  
        print() 

#1


The attribute is collidepoint(). There's no underscore.

属性是collidepoint()。没有下划线。

if event.type == pygame.MOUSEBUTTONDOWN:  
    (x, y) = event.pos  
    if Button_Start.get_rect().collidepoint(x, y):  
        print()