3

I try to implement a file manager, the question arises as using Treeview to display a directory for specified so that would have happened in TotalCommander'e

Here's a snippet of code:


from tkinter import *
from tkinter import ttk

class FileBrowser(Frame):

    def __init__(self, root):
        Frame.__init__(self, root)
        self.master.title('Файловый менеджер')
        self.master.geometry('1024x768')

        listframe = Frame(root, bd=5)
        listframe.pack(side='top', fill=BOTH, expand=1)

        self.filedirlist = ttk.Treeview(listframe)
        self.filedirlist["columns"]=("#1", "#2", "#3", "#4")
        self.filedirlist.column("#0", width=175, minwidth=100)
        self.filedirlist.column("#1", width=100, minwidth=100)
        self.filedirlist.column("#2", width=100, minwidth=100)
        self.filedirlist.column("#3", width=100, minwidth=100)
        self.filedirlist.column("#4", width=100, minwidth=100)
        self.filedirlist.heading("#0", text="Имя")
        self.filedirlist.heading("#1", text="Режим")
        self.filedirlist.heading("#2", text="Частота, МГц")
        self.filedirlist.heading("#3", text="Размер, Мб")
        self.filedirlist.heading("#4", text="Комментарий")
        self.filedirlist.pack(side='top', fill=BOTH, expand=1)
        listsb = Scrollbar(self.filedirlist,
                orient=HORIZONTAL, command=self.filedirlist.xview)
        listsb.pack(side=BOTTOM, fill=X)

        self.listbuttonopen = Button(listframe,
                text='Open').pack(side='left', padx='10', pady='5')
        self.listbuttondelete = Button(listframe,
                text='Delete').pack(side='left', padx='10', pady='5')
        self.listbuttonload = Button(listframe,
                text='Load').pack(side='left', padx='10', pady='5')

    if __name__=='__main__':
        root = Tk()
        FileBrowser(root).pack()
        root.mainloop()

When displaying folders should be active only the columns "Имя" and "Комментарий" and the remaining columns are active only when the contents of the selected folder.

Actually the question: Is it possible to implement it using Treeview'ra and how?)

P.S. Sorry for my English)

4

1 回答 1

0

您可以使用values关键字 oftkinter.ttk.Treeview.insert来更改表的特定列。您已经在使用该text选项,但后来使用values=("value1", "value2", "value3")它来指定其他列显示的内容。例如:

Take your Treeview `filedirlist`:
----------------------------------------------
|   Name   |   Type   |   Size   |   Notes   |
----------------------------------------------
|                                            |
|                                            |
|                                            |
----------------------------------------------

filedirlist.insert("", tkinter.END, "element-id1", text="example1")
----------------------------------------------
|   Name   |   Type   |   Size   |   Notes   |
----------------------------------------------
| example1                                   |
|                                            |
|                                            |
----------------------------------------------

filedirlist.insert("", tkinter.END, "element-id2", text="example2", values=("type2", "size2", "notes2"))
----------------------------------------------
|   Name   |   Type   |   Size   |   Notes   |
----------------------------------------------
| example1                                   |
| example2   type2      size2      notes2    |
|                                            |
----------------------------------------------

希望这可以帮助!

于 2014-04-19T16:20:50.433 回答