2010-12-17 100 views
4

我有以下问题: 我使用pygame,pygtk和pgu编写了Python中用于XO(OLPC机器)的问题/答案游戏。 当用户(一个孩子)写东西时,textarea(来自pgu)不需要像ñ,ó,á等特殊字符。 我只用pygame和pgu尝试过一个较小的程序,它运行良好。我认为这个问题可能与pygtk中的unicode有关,但我不知道如何检查或更正它。pygtk的Unicode问题

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() 

当我按下ñ,我进入日志文件:键ntilde无法识别。

请帮助,我卡住了,我必须提供该软件。

回答

0

当您导入gtk时,默认编码将被设置为utf-8。

import gtk, sys 
print sys.getdefaultencoding() 

因为它工作正常,没有gtk,我想这可能与编码有关。