微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

功能无法正常工作,python,pygame

如何解决功能无法正常工作,python,pygame

它只是显示一个空白显示而不是在显示底部打印开始显示没有错误

import pygame
import time

pygame.init()

black = (0,0)
white = (255,255,255)

display = pygame.display.set_mode((800,600))
pygame.display.set_caption('fitness')

font = pygame.font.SysFont(None,200)


def message_to_screen(msg,color):
    screen_text = font.render(msg,True,color)
    display.blit(screen_text,[800/2,600/2])

exercises =["pelvic shift","hanging","single leg hopping","puppy pose","side strech","low lunge                                                                               arcs","cobra strech","jogging,skipping","vertical bends","standing strechs","side bends","swimming","toe lifts","land swimming","legs up alternate","leg kicks","wake up stretchinggutes and hip bridges","forward spine stretch","cat camel back stetch","mermaid stretch","cycling","jump squats","cobra stretch","downward facing dog","bird dog","inversion table exercise","surya namaskars","side planks"]             


def exerciseLoop():  
    for x in exercises:
        for number_of_exercise in range(1,29):   
            z = exercises.index(x)
            if number_of_exercise == (z+1):
                final={}
                final.update({number_of_exercise:x})
                message_to_screen("start",black)
                clock = pygame.time.Clock()
                FPS = 30
                clock.tick(FPS)
                display.fill(white)
                pygame.display.update()
    

exerciseLoop()

解决方法

白色涂在文字上方。你需要先把它涂成白色,然后写下文字:

import pygame
import time

pygame.init()

black = (0,0)
white = (255,255,255)

Display = pygame.display.set_mode((800,600))
pygame.display.set_caption('fitness')

font = pygame.font.SysFont(None,200)


def message_to_screen(msg,color):
    screen_text = font.render(msg,True,color)
    Display.blit(screen_text,[800/2,600/2])

exercises =["pelvic shift","hanging","single leg hopping","puppy pose","side strech","low lunge                                                                               arcs","cobra strech","jogging,skipping","vertical bends","standing strechs","side bends","swimming","toe lifts","land swimming","legs up alternate","leg kicks","wake up stretchinggutes and hip bridges","forward spine stretch","cat camel back stetch","mermaid stretch","cycling","jump squats","cobra stretch","downward facing dog","bird dog","inversion table exercise","surya namaskars","side planks"]             


def exerciseLoop():  
    for x in exercises:
        for number_of_exercise in range(1,29):   
            z = exercises.index(x)
            if number_of_exercise == (z+1):
                final={}
                final.update({number_of_exercise:x})
                Display.fill(white)
                message_to_screen("start",black)
                clock = pygame.time.Clock()
                FPS = 30
                clock.tick(FPS)
                pygame.display.update()
    

exerciseLoop()
,

您必须处理应用程序循环中的事件。分别见pygame.event.get() pygame.event.pump()

对于游戏的每一帧,您都需要对事件队列进行某种调用。这可确保您的程序可以在内部与操作系统的其余部分进行交互。

def exerciseLoop():  
     
    clock = pygame.time.Clock()
    FPS = 30
    run = True
    while run:
        clock.tick(FPS)
        for event in pygame.event.get(): 
            if event.type == pygame.QUIT:
                run = False

        for x in exercises:
            for number_of_exercise in range(1,29):  
                
                z = exercises.index(x)
                if number_of_exercise == (z+1):
                    final={}
                    final.update({number_of_exercise:x})  
                
        Display.fill(white)
        message_to_screen("start",black)
                
        pygame.display.update()
    
exerciseLoop()

典型的 PyGame 应用程序循环必须:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。