我在互联网上找不到答案,所以我希望你能帮助我。我正在尝试从列表打印到 Tkinter 的文本框中。出于某种原因,当我将它打印到文本框时,它并没有按应有的方式对齐,但是当我将它打印到控制台时,它的对齐方式正确。
我使用的数据可以在data上找到。
你们中的任何人都知道可能是什么问题吗?
from tkinter import *
popup = Tk()
popup.wm_title("Podaci mreze")
widthTabela = 600
heightTabela = 500
def zatvaranje():
popup.destroy()
screenw = popup.winfo_screenwidth()
screenh = popup.winfo_screenheight()
x = screenw / 2 - widthTabela / 2
y = screenh / 2 - heightTabela / 2
popup.geometry("%dx%d+%d+%d" % (widthTabela, heightTabela, x, y))
textTFrame = Frame(popup, borderwidth=1, relief="sunken")
textTabela = Text(textTFrame, width=83, height=28.4, wrap="none", borderwidth=0)
textTVSB = Scrollbar(textTFrame, orient="vertical", command=textTabela.yview)
textTHSB = Scrollbar(textTFrame, orient="horizontal", command=textTabela.xview)
textTabela.configure(yscrollcommand=textTVSB.set, xscrollcommand=textTHSB.set, font=("Arial", 10))
textTabela.config(state="disabled")
textTabela.grid(row=0, column=0, sticky="nsew")
textTVSB.grid(row=0, column=1, sticky="ns")
textTHSB.grid(row=1, column=0, sticky="ew")
textTFrame.grid(row=0, column=0)
file=open("D:\\Pycharm_Skripte\\IEEE9.txt","r")
listaPodataka = file.readlines()
textTabela.config(state="normal")
textTabela.delete('1.0', END)
for i in range(len(listaPodataka)):
print(listaPodataka[i])
textTabela.insert(INSERT, listaPodataka[i])
textTabela.config(state="disabled")
dugmeTabela=Button(popup, text="Close", command=zatvaranje).grid(row=2, column=0)
popup.mainloop()
当前结果: