0
我想要一个按钮打印支票并运行我的铅笔功能。此刻,如果我将鼠标悬停在Box Sprite上,它将运行打印和铅笔功能。它应该是ONCLICK它运行那些2.任何人都可以帮我吗?谢谢! (这应该是所有相关的代码,如果你需要更多信息,请让我知道:)pygame按钮不会在按下/只在悬停时工作
class Box(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((35, 30))
self.image = self.image.convert()
self.image.fill((255, 0, 0))
self.rect = self.image.get_rect()
self.rect.centerx = 25
self.rect.centery = 505
self.dx = 10
self.dy = 10
while keepGoing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
box = Box()
allSprites = pygame.sprite.Group(box)
allSprites.draw(screen)
if event.type == MOUSEMOTION:
x,y = event.pos
if box.rect.collidepoint(x,y) and pygame.MOUSEBUTTONUP:
print("collide works")
pencil(background,clock,keepGoing,screen)
pygame.display.flip()
叹息...谢谢。我现在感觉非常愚蠢。所有的例子/教程等我见过..让你看起来像你检查鼠标的动作..然后检查发生的鼠标事件(即mousedown)。再次感谢。 – user1449653