我尝试实现文件管理器,问题出现在使用Treeview显示指定的目录,以便在TotalCommander'e中发生
以下是一段代码:
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()
当显示文件夹时,只应激活“Имя”和“Комментарий”列,其余列仅在所选文件夹的内容时才有效。
实际上问题是:是否可以使用Treeview'ra实现它以及如何实现?)
P.S。抱歉我的英文)
答案 0 :(得分:0)
您可以使用values
tkinter.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 |
| |
----------------------------------------------
希望这有帮助!