奇怪的故障出了Pygame Python图像

时间:2015-03-07 16:26:36

标签: python image pygame

我不知道为什么当按下按钮时它不会转到下一个功能。它回到另一个它真的很奇怪和烦人。 它应该转到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()

1 个答案:

答案 0 :(得分:0)

每次主循环重复时,都会调用'buttonPlay'。 'whattodo'内部没有任何内容可以改变这种行为,所以'whattodo'运行一次然后控制流传回主循环,它只重复'buttonPlay'。