I have the following problem: I am programmi开发者_StackOverflow中文版ng a questions/answers game for XO (OLPC machines) in python using pygame, pygtk and pgu. When the user (a kid) writes something, the textarea (from pgu) doesn't take special characters like ñ, ó, á, etc. I have tried a smaller program only with pygame and pgu and it works well. I think the problem may be with unicode in pygtk, but I don´t know how to check or correct it.
app = gui.App()#gui is from pgu
c = gui.Container(width =1200,height = 900)
background = pygame.display.get_surface()
app.init(c,background)
#load initial screen
while self.running and salir==1:
background.blit(self.pantalla,(0,0))
x,y = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
return
if event.type == pygame.KEYDOWN:
if event.unicode.isalnum():
print event.unicode
print "Evento pygame:",event.key
if event.key == pygame.K_DOWN:
exit()
app.event(event)
app.paint(background)
app.update(background)
pygame.display.flip()
#now I have to manage pygtk events:
p = gtk.events_pending()
while p:
gtk.main_iteration()
When I press ñ, i get in the log file: key ntilde unrecognized.
Please help, i'm stuck and I must deliver the software.
when you import gtk, the default encoding will be set to utf-8.
import gtk, sys
print sys.getdefaultencoding()
since it works fine without gtk, I guess it might have something to do with the encoding.
精彩评论