pygtk的Unicode问题

时间:2010-12-17 23:33:49

标签: python unicode pygtk pygame

我有以下问题: 我正在使用pygame,pygtk和pgu在python中为XO(OLPC机器)编写问题/答案游戏。 当用户(小孩)写东西时,textarea(来自pgu)不会使用ñ,ó,á等特殊字符。 我只用pygame和pgu尝试过一个较小的程序,效果很好。我认为问题可能出在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()

当我按ñ时,我进入日志文件:key ntilde unrecognized。

请帮助,我被困住了,我必须交付软件。

1 个答案:

答案 0 :(得分:0)

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

import gtk, sys
print sys.getdefaultencoding()

因为它在没有gtk的情况下工作正常,我想它可能与编码有关。

相关问题