6

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
matisetorm
  • 857
  • 8
  • 21
gin
  • 873
  • 2
  • 12
  • 23
  • 1
    I found out that if use the javascript format for this emoji : emoji = Label(labelframe, text= u'\uD83D\uDE05') it shows the emoji in tkinter, however, how can i convert the emojis to javascript format in python, i used this online converter : https://r12a.github.io/apps/conversion/ to get this \uD83D\uDE05, any ideas? – gin Dec 17 '17 at 14:42
  • I would really appreciate if there are better solutions – gin Dec 17 '17 at 15:07

1 Answers1

5

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.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • 1
    I know it's a bug because I know there's an issue number for it. Can't be bothered to look it up. Alas, it's an unfortunately messy problem to truly fix because it breaks a bunch of non-trivial assumptions. But at least you should have a reasonable workaround now… – Donal Fellows Dec 17 '17 at 17:02
  • would you recommend using another lib for gui, such as PyQt5 ? – gin Dec 17 '17 at 17:04
  • 1
    You're totally asking the wrong guy about that. I don't ever choose to use either Qt or GTK in my applications, but I'm deeply biased having written parts of Tk. – Donal Fellows Dec 17 '17 at 17:59