你可能不走运。这些 Unicode 代码点是 UTF-16 代理项。当我使用 tkinter 为您的字符串使用正确的 Unicode 代码点时,错误变为:
_tkinter.TclError: character U+1d412 is above the range (U+0000-U+FFFF) allowed by Tcl
我使用的字符串:
s = '\U0001d412\U0001d413\U0001d400\U0001d402\U0001d40a\U0001d40e\U0001d415\U0001d404\U0001d411\U0001d405\U0001d40b\U0001d40e\U0001d416.\U0001d402\U0001d40e\U0001d40c'
import unicodedata as ud
for c in s:
print(ud.name(c))
输出:
MATHEMATICAL BOLD CAPITAL S
MATHEMATICAL BOLD CAPITAL T
MATHEMATICAL BOLD CAPITAL A
MATHEMATICAL BOLD CAPITAL C
MATHEMATICAL BOLD CAPITAL K
MATHEMATICAL BOLD CAPITAL O
MATHEMATICAL BOLD CAPITAL V
MATHEMATICAL BOLD CAPITAL E
MATHEMATICAL BOLD CAPITAL R
MATHEMATICAL BOLD CAPITAL F
MATHEMATICAL BOLD CAPITAL L
MATHEMATICAL BOLD CAPITAL O
MATHEMATICAL BOLD CAPITAL W
FULL STOP
MATHEMATICAL BOLD CAPITAL C
MATHEMATICAL BOLD CAPITAL O
MATHEMATICAL BOLD CAPITAL M
我使用了 Python 3.5 文档中的“hello world”示例:
import tkinter as tk
s = '\U0001d412\U0001d413\U0001d400\U0001d402\U0001d40a\U0001d40e\U0001d415\U0001d404\U0001d411\U0001d405\U0001d40b\U0001d40e\U0001d416.\U0001d402\U0001d40e\U0001d40c'
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = s
self.hi_there["command"] = self.say_hi
self.hi_there.pack(side="top")
self.QUIT = tk.Button(self, text="QUIT", fg="red",
command=root.destroy)
self.QUIT.pack(side="bottom")
def say_hi(self):
print("hi there, everyone!")
root = tk.Tk()
app = Application(master=root)
app.mainloop()