On Mon, Jan 21, 2019, at 7:47 AM, Michael Lange wrote: > Hi again, > > sorry for my somewhat disjointed replies :) > > On Sun, 20 Jan 2019 20:30:35 +0100 > Michael Lange <klappn...@web.de> wrote: > > (...) > > l = ttk.Label(root) > > l.grid() > > l.tk.eval(l._w + ' configure -text "Test \U0001d306 String"') > > > > there is actually some character displayed which looks similar to this > > one: https://www.compart.com/en/unicode/U+1D306 , which I found rather > > surprising since with Tcl I get only a placeholder. The same happens > > when I replace your unicode character with the smiley \U0001f600 they > > used in the page I referred to before. tk.eval appears to do some magic > > here. > > tinkering a bit more I found another solution which seems more obvious, > however I was not able to get this working with Python3. With Python2 > when I do the following: > > from Tkinter import * > import ttk > > root = Tk() > l = ttk.Label(root) > l.pack(padx=40, pady=40) > > s = u'Test \U0001d306 String' > s1 = s.encode('utf-8') > l.configure(text=s1) > > root.mainloop() > > the label's text looks like expected. Maybe that is just the same "magic" > that tk.eval applies. It does not seem to be that easy with Python3 > though, apparently I missed some of the subtleties with Python3's unicode > handling mechanisms.
Thanks so much for your replies! Here's my little test script, with trying what you wrote, and the results I got (all on python 3): import tkinter as tk from tkinter import ttk root = tk.Tk() l = ttk.Label(root) l.grid(row=0, column=0) text = 'Test \U0001d306 String' #l.configure(text=text) # Result: _tkinter.TclError: character U+1d306 is above the range (U+0000-U+FFFF) allowed by Tcl #l.configure(text=text.encode('utf8')) # Result: no exception, but wrong characters show up l.tk.eval(l._w + f' configure -text "{text}"') # Result: works! root.mainloop() So, tkinter maintainers, would there be a way to build this into tkinter, so it transparently handles all unicode characters? If so, would there be interest in patches for it? -Ben _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss