我有以下Python(3.7.2)代码:
import tkinter as tk
root = tk.Tk()
art = '''
uu$$$$$$$$$$$uu
uu$$$$$$$$$$$$$$$$$uu
u$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$$$$$$$$$$$$$$$$$$$$u
u$$$$$$* *$$$* *$$$$$$u
*$$$$* u$u $$$$*
$$$u u$u u$$$
$$$u u$$$u u$$$
*$$$$uu$$$ $$$uu$$$$*
*$$$$$$$* *$$$$$$$*
u$$$$$$$u$$$$$$$u
u$*$*$*$*$*$*$u
uuu $$u$ $ $ $ $u$$ uuu
u$$$$ $$$$$u$u$u$$$ u$$$$
$$$$$uu *$$$$$$$$$* uu$$$$$$
u$$$$$$$$$$$uu ***** uuuu$$$$$$$$$
$$$$***$$$$$$$$$$uuu uu$$$$$$$$$***$$$*
*** **$$$$$$$$$$$uu **$***
uuuu **$$$$$$$$$$uuu
u$$$uuu$$$$$$$$$uu **$$$$$$$$$$$uuu$$$
$$$$$$$$$$**** **$$$$$$$$$$$*
*$$$$$* **$$$$**
$$$* $$$$*
'''
print(art)
label = tk.Label(text=art)
label.pack()
root.mainloop()
它将在控制台和Tkinter中打印头骨。但是在Tkinter中,其格式错误。 (不会引发任何错误)
问题
This是唯一相关的帖子,但没有帮助。
答案 0 :(得分:4)
您需要使用等宽字体来使ASCII艺术作品正常工作。使用此示例:
import Tkinter
import ttk
style = ttk.Style()
style.configure('Style.TButton', font='TkFixedFont')
label = tk.Label(text=art, style='Style.TButton')