Am 09.01.2011 21:59, schrieb Floris van Manen:
you could try
text = font.render("Hello world!", 1, (255, 255, 0,255), None)
Ok. I did. But it doesn't work either.
I'm especially puzzled, because this is against the way I thought
Python would handle keyword arguments.
Clearly None is an invalid RGBA argument, as the error message states.
But according to the docs the parameter background has as its
default value None. Why is it, that settig background to its default value
doesn't work, while it works well when I leave it out, in which case it
should
also have the value None?
Are these two different None-s?
Who knows an explanation?
Who knows a workaround for this sort of usage:
def text_line(surface, font, text, x, y, color, bg=None):
...
label = font.render(text, 1, color, bg)
...
which fails if bg is not given.
Best regards,
Gregor
On Jan 9, 2011, at 21:31, 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