奇怪的Pygame Python图像

2024-04-26 20:57:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道为什么当按下按钮时,它不只是进入下一个功能。它又回到了另一个它真的很奇怪很烦人。 它应该转到whattodo函数,但它只运行了半秒钟,然后转到另一个。有人知道为什么吗?你知道吗

#!/usr/bin/python
import pygame
pygame.init()
screen = pygame.display.set_mode((1400,700))
pygame.display.set_caption("Anti-Docter")
titlescreen = pygame.image.load('titleframe.bmp')
boxinfo = pygame.image.load('boxinfo.bmp')
black = (0,0,0)
white = (255,255,255)
randommommycolor = (255,139,12)
Brown = (102,51,0)
Lighter_Brown = (120,59,5)
def mts(text, textcolor, x, y, fs):
    font = pygame.font.Font(None,fs)
    text = font.render(text, True, textcolor)
    screen.blit(text, [x,y])
def buttonPlay(x,y,w,h,ic,ac):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    if x+w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(screen, ac,(x,y,w,h))

        if click[0] == 1:
            whattodo()
    else:
        pygame.draw.rect(screen, ic,(x,y,w,h))
def whattodo():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
    screen.blit(boxinfo, (0,0))
    pygame.display.update()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
    screen.blit(titlescreen, (0,0))
    buttonPlay(580, 350, 200, 90, Brown, Lighter_Brown)
    mts("Play", black, 620, 365, 80)
    pygame.display.update()

Tags: texteventgetifdefdisplayscreenpygame
1条回答
网友
1楼 · 发布于 2024-04-26 20:57:27

每次主循环重复时,它都会调用“buttonPlay”。“whattodo”中没有任何东西可以改变这种行为,因此“whattodo”只运行一次,然后控制流返回到主循环,主循环只重复“buttonPlay”。你知道吗

相关问题 更多 >