Displaying emojis/symbols in Python using tkinter lib

天大地大妈咪最大 提交于 2019-12-28 18:39:25

问题


Does Tkinter support 16bit range characters, because I can not print emojis in the gui, when printing in python terminal, it works fine

>> print("😊")
>> 😊

but in tkinter, it shows this error:

_tkinter.TclError: character U+1f618 is above the range (U+0000-U+FFFF) allowed by Tcl

回答1:


There's a bug in Tkinter that it doesn't transparently map this for you, and definitely a bug in the underlying libraries (Tcl and Tk) that the string is not accepted as is and needs intervention at all. The state is that the underlying libraries currently require that the non-BMP characters in strings be encoded as surrogate pairs.

A little searching here provides code for actually doing this encoding.

  • Python: Find equivalent surrogate pair from non-BMP unicode char


来源:https://stackoverflow.com/questions/47855762/displaying-emojis-symbols-in-python-using-tkinter-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!