我试图在python中读取.txt文件,它在控制台中可以正常工作,但是当我尝试将其放在Label(tkinter)中时,文本结构是错误的。信息是正确的,但行的位置略有偏离,这使其难以阅读
我尝试了不同的小部件,并逐行打印文本。
def bada_search():
aircraft_search = bada_entry.get()
try:
with open("BADA\\" + str(aircraft_search) + "__.PTF", "rt") as file:
dane = file.read()
bada_window= Toplevel()
bada_dane= Label(bada_window, text= dane).pack()
print(dane)
except:
print("Aircraft not found")
答案 0 :(得分:0)
我假设您正在谈论文本对齐方式。您需要使用等宽字体,例如Consolas
:
def bada_search():
aircraft_search = bada_entry.get()
try:
with open("BADA\\" + str(aircraft_search) + "__.PTF", "rt") as file:
dane = file.read()
bada_window= Toplevel()
bada_dane= Label(bada_window,text= dane,font="Consolas 9").pack()
print(dane)
except:
print("Aircraft not found")