Start New Discussion within our Software Development Community

Okay everyone first heres a source page for this module that im having trouble with...

http://www.pygame.org/docs/ref/font.html


Anyways my problem is finding out how to use this module to be able to print a variable with font.render....... anyone know how? Heres the code...

#! usr/bin/env python

import pygame, sys, os
from pygame.locals import *
pygame.font.init

pygame.init()

screen = pygame.display.set_mode((150, 150))
pygame.display.set_caption('Help')
pygame.mouse.set_visible(0)
pygame.display.init()

lives = 3

def main():
        global lives
	font = pygame.font.Font(None, 36)
	text = font.render("Lives =" [B][U][I][somehow but number of lives here][/I][/U][/B]", 1, (250, 250, 250))
	screen.blit(text, (0, 0))
        pygame.display.flip()

main()

So can anyone figure out how i can do this without an error message popping up? THANKS!!!

Something like this will do:

#! usr/bin/env python

import pygame
from pygame.locals import *

pygame.font.init

pygame.init()

screen = pygame.display.set_mode((150, 150))
pygame.display.set_caption('Help')
pygame.mouse.set_visible(0)
pygame.display.init()

lives = 3

def main():
    global lives
    font = pygame.font.Font(None, 36)
    s = "Lives =" + str(lives)
    text = font.render(s, 1, (250, 250, 250))
    screen.blit(text, (0, 0))
    pygame.display.flip()
    # run event loop and provide exit conditions
    while True:
        for event in pygame.event.get():
            # window title 'x' click
            if event.type == pygame.QUIT:
                raise SystemExit

main()
This article has been dead for over six months. Start a new discussion instead.