如何排列列表框python中的文本

时间:2013-05-24 04:01:22

标签: python string python-2.7 listbox formatting

我有三个列表填充列表框。我想知道的是有一种方法来格式化短语,使名称全部符合日期,然后是信息。我试图用+来组合所有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)

1 个答案:

答案 0 :(得分:0)

您可以使用滚动条小部件:

self.scrollbar=Scrollbar(self.showWindow, orient=HORIZONTAL)
self.scrollbar.pack(side=BOTTOM, fill=X)

self.listBox= Listbox(self.showWindow, height=10, width=80, xscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.listBox.xview)

有关详细信息,您可以看到: http://effbot.org/tkinterbook/scrollbar.htm