[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Strange (uncommon) behaviour of Font.render()



Hi,

Actually the documentation is inconsistent. The last argument is optional. Omit it to use the default background color. But yes, this should be fixed. It will be considered a bug. Thanks for bringing it up.

Lenard Lindstrom

On 09/01/11 12:31 PM, Gregor Lingl wrote:
Executing the script

import pygame

pygame.init()
screen = pygame.display.set_mode((400, 300))

font = pygame.font.SysFont("Arial", 64)
text = font.render("Hello world!", 1, (255, 255, 0), None)
screen.blit(text, (72, 113))
pygame.display.flip()

pygame.event.clear()
pygame.event.wait()

results in an exception:

Traceback (most recent call last):
File "C:\Dokumente und Einstellungen\Entwickler\Eigene Dateien\My Dropbox\___pygame4kids___\kapitel04\programme\render_problem.py", line 9, in <module>
    text = font.render("Hello world!", 1, (255, 255, 0), None)
TypeError: Invalid background RGBA argument

In the docs for pygame.font.Font() one reads:

Font.render
     draw text on a new Surface
     Font.render(text, antialias, color, background=None): return Surface

     ...

See:
http://www.pygame.org/docs/ref/font.html#pygame.font.Font

So, because in Python

>>> None is None
True

I expected the call

font.render("Hello world!", 1, (255, 255, 0), None)

to have the same effect as

font.render("Hello world!", 1, (255, 255, 0))

So, what's the matter? What am I missing?

Best regards,
Gregor