在 pygame 中编写文本 [英] Writing text in pygame

查看:71
本文介绍了在 pygame 中编写文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在 pygame 中显示文本,但我真正需要的是能够在 pygame 窗口已经运行时编写文本.

I know how to display text in pygame, but what I really need is to be able to write a text when the pygame window is already running.

这是我的 pygame 窗口代码:导入pygame

this is my pygame window code: import pygame

def highscore():
    pygame.font.init()
    background_colour = (255,255,255)
    (width, height) = (600, 600)

    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption('Tutorial 1')
    screen.fill(background_colour)

    pygame.display.flip()

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False



highscore()

推荐答案

http://www.daniweb.com/software-development/python/code/244474/pygame-text-python

这是一个示例的链接……我认为您正在寻找的代码是这样的……

Here's a link to an example... the code you're kinda looking for is this I think...

# pick a font you have and set its size
myfont = pg.font.SysFont("Comic Sans MS", 30)
# apply it to text on a label
label = myfont.render("Python and Pygame are Fun!", 1, yellow)
# put the label object on the screen at point x=100, y=100
screen.blit(label, (100, 100))

这篇关于在 pygame 中编写文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆