This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
forked from OpenStudioCorp/PythonicOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_folder.py
58 lines (47 loc) · 2.28 KB
/
load_folder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import tkinter as tk
from tkinter import ttk
import os
root = tk.Tk()
root.title("PythonOS file explorer")
root.geometry("640x480")
taskbar = tk.Frame(root, height=40,bg='lightgrey')
taskbar.pack(side=tk.TOP, fill=tk.X)
desktop = tk.Frame(root, bg='grey')
desktop.pack(expand=True, fill=tk.BOTH)
desktop.bind("<Button-3>", lambda event: file_context_menu.delete(0, tk.END))
file_context_menu = tk.Menu(root, tearoff=False)
script_dir = os.path.dirname(os.path.abspath(__file__))
def load_files(files_, directory_path):
for widget in desktop.winfo_children():
widget.destroy()
# Create a frame to hold the file explorer widget
file_explorer_frame = tk.Frame(desktop, bd=2, relief='sunken')
file_explorer_frame.pack(side='left', fill='y')
# Create a treeview widget to display the directory structure
tree = ttk.Treeview(file_explorer_frame)
tree.pack(side='left', fill='y')
tree.bind("<Double-1>", lambda event: open_file(tree))
# Create a scrollbar for the treeview widget
scrollbar = ttk.Scrollbar(file_explorer_frame, orient="vertical", command=tree.yview)
scrollbar.pack(side='right', fill='y')
tree.configure(yscrollcommand=scrollbar.set)
# Add the root node to the treeview
root_node = tree.insert('', 'end', text=directory_path, open=True)
# Add child nodes to the root node for each file and directory in the specified directory
for file in os.listdir(directory_path):
file_path = os.path.join(directory_path, file)
if os.path.isdir(file_path):
dir_node = tree.insert(root_node, 'end', text=file, open=False)
add_nodes_to_tree(tree, dir_node, file_path)
else:
tree.insert(root_node, 'end', text=file)
def add_nodes_to_tree(tree, parent_node, directory_path):
# Recursively add child nodes to the parent node for each file and directory in the specified directory
for file in os.listdir(directory_path):
file_path = os.path.join(directory_path, file)
if os.path.isdir(file_path):
dir_node = tree.insert(parent_node, 'end', text=file, open=False)
add_nodes_to_tree(tree, dir_node, file_path)
else:
tree.insert(parent_node, 'end', text=file)
load_files()