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

Re: [pygame] How the get a font size



Hi,

James Paige wrote:
The only bad thing I can say about it is that it simply doesn't work :(

f = pygame.font.Font(None, 12)
f.size = 12
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'pygame.font.Font' object attribute 'size' is read-only

And that is not just because Font already has a method named .size()

f.pointsize = 12
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'

I'm guessing that since pygame.font.Font is impelmented in C, it doesn't allow new members to be added as it would if it was implemented in python (Correct me if I am wrong)

You're right. Font instances lack attribute dictionaries. It was a design decision, or omission, and not a restriction of Font being implemented in C.

---
James Paige

On Tue, Jan 13, 2009 at 01:54:30AM +0200, Thiago Chaves wrote:
You can also just violate the object by giving it an extra attribute:

f = pygame.font.Font(filename, size)
f.new_attribute = size



--
Lenard Lindstrom
<len-l@xxxxxxxxx>