在 Pygame 中将鼠标悬停在按钮上时光标不会改变 [重复]

问题描述 投票:0回答:0

当用户将鼠标悬停在 pygame 中的按钮上时,我正在尝试更新光标。

目前,鼠标悬停在按钮上时,光标会在“手”和“箭头”之间闪烁

这是 Button 类的代码:

`导入pygame

类按钮(): def init(self, x, y, image): self.image = 图片 self.rect = self.image.get_rect() self.rect.topleft = (x,y) self.clicked = False

def draw(self, surface):

    action = False
    #get mouse position
    pos = pygame.mouse.get_pos()
    
    #check if mouseover and clicked conditions
    if self.rect.collidepoint(pos):
        pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)
        if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
            self.clicked  = True
            action = True
    else:
        pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)

    if pygame.mouse.get_pressed()[0] == 0:
        self.clicked = False

    # draw button on screen
    surface.blit(self.image, (self.rect.x, self.rect.y))

    return action`

以及主类的相关代码:

`def start_menu(窗口): START_MENU = 真 全局 MUSIC_MUTED

while START_MENU:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()


    draw(window, background, bg_image, floor, ceiling, wall1, wall2)
    if start_button.draw(window):
        gameloop(window)
        START_MENU = False

    if background_mute_button.draw(window):
        toggle_music()

    pygame.display.flip()`
pygame
© www.soinside.com 2019 - 2024. All rights reserved.