【问题标题】:how to line up text in list box python如何在列表框中排列文本python
【发布时间】:2013-05-19 14:42:46
【问题描述】:

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

【问题讨论】:

    标签: python string python-2.7 listbox formatting


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      相关资源
      最近更新 更多