pygame / examples /

#!/usr/bin/env python

"""Here we load a .TTF font file, and display it in
a basic pygame window. It demonstrates several of the
Font object attributes. Nothing exciting in here, but
it makes a great example for basic window, event, and
font management."""

import pygame
from pygame.locals import *
from pygame.compat import unichr_, unicode_
import sys
import locale

if sys.version_info >= (3,):
    def print_unicode(s):
        e = locale.getpreferredencoding()
        print (s.encode(e, 'backslashreplace').decode())
    def print_unicode(s):
        e = locale.getpreferredencoding()
        print (s.encode(e, 'backslashreplace'))

def main():
    resolution = 400, 200
    screen = pygame.display.set_mode(resolution)

##    pygame.mouse.set_cursor(*pygame.cursors.diamond)

    fg = 250, 240, 230
    bg = 5, 5, 5
    wincolor = 40, 40, 90

    #fill background

    #load font, prepare values
    font = pygame.font.Font(None, 80)
    text = 'Fonty'
    size = font.size(text)

    #no AA, no transparancy, normal
    ren = font.render(text, 0, fg, bg)
    screen.blit(ren, (10, 10))

    #no AA, transparancy, underline
    ren = font.render(text, 0, fg)
    screen.blit(ren, (10, 40 + size[1]))

    a_sys_font = pygame.font.SysFont("Arial", 60)

    #AA, no transparancy, bold
    ren = a_sys_font.render(text, 1, fg, bg)
    screen.blit(ren, (30 + size[0], 10))

    #AA, transparancy, italic
    ren = a_sys_font.render(text, 1, fg)
    screen.blit(ren, (30 + size[0], 40 + size[1]))

    # Get some metrics.
    print ("Font metrics for 'Fonty':  %s" % a_sys_font.metrics (text))
    ch = unicode_("%c") % 0x3060
    msg = (unicode_("Font metrics for '%s':  %s") %
           (ch, a_sys_font.metrics (ch)))

    ## #some_japanese_unicode = u"\u304b\u3070\u306b"
    ##some_japanese_unicode = unicode_('%c%c%c') % (0x304b, 0x3070, 0x306b)
    #AA, transparancy, italic
    ##ren = a_sys_font.render(some_japanese_unicode, 1, fg)
    ##screen.blit(ren, (30 + size[0], 40 + size[1]))

    #show the surface and await user quit
    while 1:
        #use event.wait to keep from polling 100% cpu
        if pygame.event.wait().type in (QUIT, KEYDOWN, MOUSEBUTTONDOWN):

if __name__ == '__main__': main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.