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

Re: [pygame] getting what an user has written



In a message of Tue, 22 Jan 2008 13:53:01 +0100, 110110010 writes:
>Hello. I use this script in a class to get the string what user had writt
>en:
>string.string=u""
>strfont=pygame.font.Font(None,16)
>for udalost in pygame.event.get():
>          if udalost.type == KEYDOWN:
>            if udalost.key == K_RETURN: exit=1
>            elif udalost.key == K_BACKSPACE: 
>              self.string=self.string[:-1]
>              text=strfont.render(self.string,0,(0,0,0))
>            elif not strfont.size(self.string+udalost.unicode)[0]>mw-8:
>              self.string+=udalost.unicode
>              text=strfont.render(self.string,0,(0,0,0))
>
>Everything works fine except that i get unicode string in another encodin
>g, which I don't want. Can somebody tell me which coding pygame uses and/
>or how to translate it to utf-8 encoding?

This is how I am handling iso-8859-1

# raw is some string I just got from a user.
fileencoding = "iso-8859-1"
txt = raw.decode(fileencoding)

I strongly suspect that if you replace iso-9959-1 with utf-8 in the above
it will just start working for you.

Laura