[Tkinter-discuss] ttk.Label unicode characters
Michael Lange
klappnase at web.de
Mon Jan 21 07:47:30 EST 2019
Hi again,
sorry for my somewhat disjointed replies :)
On Sun, 20 Jan 2019 20:30:35 +0100
Michael Lange <klappnase at 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.
Regards
Michael
.-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
The joys of love made her human and the agonies of love destroyed her.
-- Spock, "Requiem for Methuselah", stardate 5842.8
More information about the Tkinter-discuss
mailing list