繁体   English   中英

python和pygame字体居中工作,但我不知道为什么

[英]python and pygame font centering is working but I don't know why

尽管我完全不知道为什么,但我的代码运行良好。

我的代码是:

def textobjects(message, font,color):
    Textsurface = font.render(message, True, color)
    return Textsurface, Textsurface.get_rect()

def Display_text(message,color):
    Heading = pygame.font.SysFont("Arial",70)
    TextShown, Textrect = textobjects(message, Heading,color)
    Textrect.center = ((displaywidth/2),0)
    gameWindow.blit(TextShown,Textrect)
    pygame.display.update()
    time.sleep(2)
    game_loop()


def border():
    Display_text("You hit the border",wine)

而且我不知道为什么能做到:

Textrect.center = ((displaywidth/2),0)

无需定义“ .center”。 .center是pygame / python预定义模块吗?

.center是您可以获取和设置的rect对象的一部分

你也可以

Rect.left
Rect.top
Rect.right
Rect.bottom
Rect.topleft
Rect.bottomleft
Rect.topright
Rect.bottomright
Rect.centerx
Rect.centery

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM