繁体   English   中英

Python TTK TreeView 排序

[英]Python TTK TreeView sorting


我一直在制作(尝试)制作一个程序,您可以使用 ttk TreeView 小部件浏览目录!
我想要顶部的文件夹和它们之后的文件。 但我就是没弄好...

这是我的代码:

from tkinter import *
import os
root = Tk()
root.title("RemotExplorer")
root.geometry("500x500")
tree = ttk.Treeview(root)
tree['columns'] = ("Type")
tree.column("#0", width=320, minwidth=119)
tree.column("Type", width=101, minwidth=100)
tree.heading("#0", text="Name", anchor=W)
tree.heading("Type", text="Type", anchor=W)
did = os.listdir()
folders = next(os.walk('.'))[1]
files = next(os.walk(os.getcwd()))[2]
for content in did:
    if content in folders:
        tree.insert(parent='', index=did.index(content), iid=did.index(content), text=content, values=("Folder"))
    else:
        continue
for content in did:
    if content in files:
        tree.insert(parent='', index=did.index(content), iid=did.index(content), text=content, values=("File"))
    else:
        continue
tree.pack(pady=20, padx=10)
root.mainloop()```


我一直在制作(尝试)制作一个程序,您可以使用 ttk TreeView 小部件浏览目录!
我想要顶部的文件夹和它们之后的文件。 但我就是没弄好...

这是我的代码:

from tkinter import *
import os
root = Tk()
root.title("RemotExplorer")
root.geometry("500x500")
tree = ttk.Treeview(root)
tree['columns'] = ("Type")
tree.column("#0", width=320, minwidth=119)
tree.column("Type", width=101, minwidth=100)
tree.heading("#0", text="Name", anchor=W)
tree.heading("Type", text="Type", anchor=W)
did = os.listdir()
folders = next(os.walk('.'))[1]
files = next(os.walk(os.getcwd()))[2]
for content in did:
    if content in folders:
        tree.insert(parent='', index=did.index(content), iid=did.index(content), text=content, values=("Folder"))
    else:
        continue
for content in did:
    if content in files:
        tree.insert(parent='', index=did.index(content), iid=did.index(content), text=content, values=("File"))
    else:
        continue
tree.pack(pady=20, padx=10)
root.mainloop()```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM