8.20: makeTextObjs(), A Shortcut Function for Making Text

Making Games with Python and Pygame · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    8.20: makeTextObjs(), A Shortcut Function for Making Text
    def makeTextObjs(text, font, color):
        surf = font.render(text, True, color)
        return surf, surf.get_rect()
    

    The makeTextObjs() function just provides us with a shortcut. Given the text, Font object, and a Color object, it calls render() for us and returns the Surface and Rect object for this text. This just saves us from typing out the code to create the Surface and Rect object each time we need them.


    This page titled 8.20: makeTextObjs(), A Shortcut Function for Making Text was last modified on Fri, 08 Nov 2019 04:30:02 GMT and is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Al Sweigart via source content that was edited to the style and standards of the LibreTexts platform.