Tkinter 中的 ASCII 艺术在控制台中看起来不像
ASCII art in Tkinter doesn't look like in console
我有这个 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 中,它的格式不正确。 (没有抛出错误)
问题
- 为什么 Tkinter (Label) 有另一种格式?
- 我该如何解决?
This 是唯一相关的 post,但没有帮助。
您需要使用等宽字体才能使 ASCII 艺术作品正常工作。使用这个例如:
import Tkinter
import ttk
style = ttk.Style()
style.configure('Style.TButton', font='TkFixedFont')
label = tk.Label(text=art, style='Style.TButton')
我有这个 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 中,它的格式不正确。 (没有抛出错误)
问题
- 为什么 Tkinter (Label) 有另一种格式?
- 我该如何解决?
This 是唯一相关的 post,但没有帮助。
您需要使用等宽字体才能使 ASCII 艺术作品正常工作。使用这个例如:
import Tkinter
import ttk
style = ttk.Style()
style.configure('Style.TButton', font='TkFixedFont')
label = tk.Label(text=art, style='Style.TButton')