使用unicode字符与wxPython [英] using unicode characters with wxPython

查看:212
本文介绍了使用unicode字符与wxPython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题wxpython和他的富文本控制,当我尝试插入unicode字符... \xb2打印顶点'2','\\\⁴'应打印顶点'4'...

编辑:我使用windows vista ...我试图编码cp1252和utf-8但具有相同的结果...

2edit:
在vista它崩溃,在xp它显示一个奇怪的广场(我猜是的,当pc不能识别的字符...)

i have a problem with wxpython and his rich text control, when I try to insert unicode characters... \xb2 prints an apex '2', '\u2074' should print an apex '4'...
edit: I use windows vista... and I tried 'coding cp1252 ' and 'utf-8' but with the same result...
2edit: on vista it crashs, on xp it shows a strange square (i guess it's when the pc doesn't recognize the character...)

这里是源代码:

from __future__ import unicode_literals

import wx
import wx.richtext as rt

class Trial(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Prova', 
                size=(400, 400))

        self.rtc = rt.RichTextCtrl(self, style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER)
        wx.CallAfter(self.rtc.SetFocus)
        #self.rtc.Freeze()
        self.rtc.BeginFontSize(14)
        self.rtc.WriteText('hei!\xb2') #alright
        self.rtc.WriteText('hi\u2074!')#crash
        self.rtc.EndFontSize()
        
       
if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Trial()
    frame.Show()
    app.MainLoop()

但是当我尝试运行它时,会崩溃...

but when I try to run it, it crashs...

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    frame = display.Trial()
  File "C:\Users\expert\Desktop\display.py", line 15, in __init__
    self.rtc.WriteText('hi\u2074!')
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\richtext.py", line 2507, in WriteText
    return _richtext.RichTextCtrl_WriteText(*args, **kwargs)
  File "C:\Python26\lib\encodings\cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2074' in position 4: character maps to <undefined>

所以...我该怎么办?我真的需要显示它...

so...what should I do? I really need to show it...

感谢大家!

推荐答案

如果你想要Unicode支持,那么你应该使用unicode版本的wxpython。

If you want Unicode support then you should be using the unicode version of wxpython.


有两个版本的wxPython for
每个受支持的Python版本
在Win32上。它们几乎相同,
,除了其中之一已编译
,并支持Unicode版本
的平台API。除非你有
被告知不同,你可能
想得到
wxPython的Unicode构建。

There are two versions of wxPython for each of the supported Python versions on Win32. They are nearly identical, except one of them has been compiled with support for the Unicode version of the platform APIs. Unless you've been told differently, you probably want to get the Unicode build of wxPython.

大多数其他平台也有两个版本。

Most other platforms also have two versions.

如果你传递实际的符号,它可以正常工作

It works fine if you pass the actual symbols e.g

self.rtc.WriteText("hei!²")

这篇关于使用unicode字符与wxPython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆