我有三个列表填充列表框。我想知道的是有没有一种方法来格式化短语,以便名称全部对齐,然后是日期,然后是信息。我曾尝试使用 + 来组合所有 3 个三个部分,但只要名称更大或更小,其他所有部分就会变得不合时宜。
class showTask:
def __init__(self):
self.showWindow = Tk()
self.showWindow.configure(background = "black")
self.showWindow.geometry("750x750")
self.showWindow.resizable(width = False, height = False)
self.showWindow.title("Show All Tasks")
self.listBox = Listbox(self.showWindow,height = 10, width = 80)
self.listBox.place(relx = 0.02, rely = 0.2)
self.showButton = Button(self.showWindow, height = 5, width = 20, text="Search for Task",highlightbackground="black",font=("Helvetica",10,"bold"),command=lambda:self.showFuntion())
self.showButton.place(relx = 0.01,rely = 0.05)
def showFuntion(self):
self.listBox.delete(0,END)
self.file = open("dataFile.txt", "r+")
fileData = self.file.readlines()
self.file.close()
counter = 1
self.name = []
self.date = []
self.details = []
lengthOfFile = len(fileData)
for i in range (lengthOfFile):
split = fileData[i].split("\n")
while counter == 1:
self.name.append(split)
break
while counter == 2:
self.date.append(split)
break
while counter == 3:
self.details.append(split)
break
counter = counter +1
if counter > 3:
counter = 1
for x in range(len(self.name)):
line = self.name[x][0]+"|"+self.date[x][0]+"|"+self.details[x][0]
self.listBox.insert(END,line)