我正在使用 Python-GTK,我想在 GTK 条目中使用 permille 字符——看起来像 ‰ o/oo。GTK 使用 Unicode,或更准确地说是 UTF-8。
我实际上做的是以这种方式从 XML 中读取字符串:
self.xdb = ElementTree.parse("myfile.xml")
xmap = self.xdb.getiterator(tag="map")
for x in xmap:
unit = x.get("unit","")
XML 文件是这样写的:
<map idx='398' unit='\u2030' />
然后我以这种方式将字符串(在本例中为 '\u2030')转换为 Unicode:
unistring = ""
for s in unit:
unistring += unichr(ord(s))
然后我用转换后的字符串设置 gtk-entry 的文本:
entry.set_text(unistring)
但条目中的文本显示 '\u2030' 而不是预期的字符。
有谁知道如何处理这个?
谢谢。