Python 循环内(函数内)文本未更新

Python 循环内(函数内)文本未更新,python,pygame,Python,Pygame,我试图用Python制作自己的OLDTV版本,但遇到了一个问题。我正在制作一个效果,文本在变为常规大小之前会变大一段时间。我遇到的问题是文本根本不显示。我正在运行Anaconda2.7(安装在以前的项目中),并附带Spyder编辑器(如果有帮助的话) 代码: 导致故障的部分是displayWordCol函数。我的代码有问题吗,还是应该切换到空闲并粘贴到代码中?我认为主要问题是使用scale()缩放渲染文本。据我所知,scale()用于图像 试着把它作为一个简单的例子(你可以在以后根据自己的需要进

我试图用Python制作自己的OLDTV版本,但遇到了一个问题。我正在制作一个效果,文本在变为常规大小之前会变大一段时间。我遇到的问题是文本根本不显示。我正在运行Anaconda2.7(安装在以前的项目中),并附带Spyder编辑器(如果有帮助的话)

代码:


导致故障的部分是displayWordCol函数。我的代码有问题吗,还是应该切换到空闲并粘贴到代码中?

我认为主要问题是使用scale()缩放渲染文本。据我所知,scale()用于图像

试着把它作为一个简单的例子(你可以在以后根据自己的需要进行调整)

另一个可能的问题是,您可能需要在每个循环周期(不确定您正在寻找哪种效果)中闪烁单词之前擦除屏幕

最后,使用pygame几乎总是一件好事,使用“脏”矩形,只删除和更新屏幕上实际更改的部分

问候

编辑:也试试这个。我添加了在blitting之前擦除屏幕。我想这就是你想要的效果。我还添加了“dirty”rects管理作为示例

def displayWordCol(word, col):
    colVal = [(255, 0, 0), (255, 128, 0), (190, 190, 0), (0, 255, 0), (0, 0, 255), (128, 0, 255)]
    regular_size = 72
    cicles = 20
    size_gap = 5

    initial_size = regular_size + cicles * size_gap
    text = create_text(word, font_preferences, int(initial_size), colVal[col - 1])
    pos = (320, 240)
    rect = pygame.Rect(pos[0] - text.get_width()/2, pos[1] - text.get_height()/2, text.get_width(), text.get_height())

    screen.fill(pygame.Color("white"))
    pygame.display.update()
    for i in range(cicles):
        text = create_text(word, font_preferences, int(initial_size - i*size_gap), colVal[col-1])
        screen.fill(pygame.Color("white"), rect)
        screen.blit(text, (pos[0] - text.get_width()/2, pos[1] - text.get_height()/2))
        pygame.display.update(rect)
        clock.tick(60))

我想把它缩进去,但那也留下了旧的。我怎样才能摆脱它?(不过,这个例子很有效。谢谢你!哦,我明白了。你的代码准备增加文本,而不是缩小文本。你必须“玩”文本的大小和位置。对于大小,这部分是键:int(72*I/5),你可以在其中使用类似:int(72+10*2)-I*2的东西)。。。和类似的位置计算以前的位置和大小,以放置新文本。除此之外,最简单的方法是删除并更新初始(更大的)rect。我编辑了我的答案,以调整函数以缩小文本,而不是增加文本。试一试并发表评论!
def displayWordCol(word, col):
colVal = [(255, 0, 0), (255, 128, 0), (190, 190, 0), (0, 255, 0), (0, 0, 255), (128, 0, 255)]
    for i in range(10):
        text = create_text(word, font_preferences, int(72 *i/5), colVal[col-1])
        #scale(text, (text.get_width() * i/5, text.get_height() * i/5))
        screen.blit(text, (320 - text.get_width() // 2, 240 - text.get_height() // 2))
        pygame.display.update()
        clock.tick(60)
def displayWordCol(word, col):
    colVal = [(255, 0, 0), (255, 128, 0), (190, 190, 0), (0, 255, 0), (0, 0, 255), (128, 0, 255)]
    regular_size = 72
    cicles = 20
    size_gap = 5

    initial_size = regular_size + cicles * size_gap
    text = create_text(word, font_preferences, int(initial_size), colVal[col - 1])
    pos = (320, 240)
    rect = pygame.Rect(pos[0] - text.get_width()/2, pos[1] - text.get_height()/2, text.get_width(), text.get_height())

    screen.fill(pygame.Color("white"))
    pygame.display.update()
    for i in range(cicles):
        text = create_text(word, font_preferences, int(initial_size - i*size_gap), colVal[col-1])
        screen.fill(pygame.Color("white"), rect)
        screen.blit(text, (pos[0] - text.get_width()/2, pos[1] - text.get_height()/2))
        pygame.display.update(rect)
        clock.tick(60))