gpt4 book ai didi

Python:如何检测鼠标何时单击图像?

转载 作者:太空宇宙 更新时间:2023-11-03 17:43:32 26 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于Python:如何检测鼠标何时单击图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30141470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com