Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- from tkinter import messagebox, ttk
- def load_folders():
- folders = []
- try:
- with open('FOLDERS.txt', 'r', encoding='utf-8', errors='replace') as file:
- folders = [line.strip() for line in file if line.strip()]
- except FileNotFoundError:
- messagebox.showerror("Error", "FOLDERS.txt file not found.")
- return folders
- def load_commands():
- commands = []
- try:
- with open('Commands.txt', 'r', encoding='utf-8', errors='replace') as file:
- commands = [line.strip() for line in file if line.strip()]
- except FileNotFoundError:
- messagebox.showerror("Error", "Commands.txt file not found.")
- return commands
- def list_items(search_term=None):
- listbox.delete(0, tk.END)
- for folder in folders:
- if os.path.exists(folder):
- for item in os.listdir(folder):
- if not search_term or search_term.lower() in item.lower():
- listbox.insert(tk.END, item)
- else:
- messagebox.showerror("Error", f"Folder not found: {folder}")
- def search_items():
- search_term = search_entry.get()
- list_items(search_term)
- def open_selected(event=None):
- selected = listbox.get(tk.ACTIVE)
- if selected:
- for folder in folders:
- full_path = os.path.join(folder, selected)
- if os.path.exists(full_path):
- # Check if the selected file has an allowed extension
- if selected.endswith(('.txt', '.py', '.pyw', '.ahk', '.bat', '.m3u', '.m3u8', '.reg', '.vbs', '.ls')):
- try:
- with open(full_path, 'r', encoding='utf-8', errors='replace') as file:
- second_result_text.delete(1.0, tk.END)
- second_result_text.insert(tk.END, file.read())
- second_result_text.config(state=tk.NORMAL) # Ensure the second result_text field is editable
- except Exception as e:
- messagebox.showerror("Error", str(e))
- else:
- os.startfile(full_path)
- break
- def run_command():
- command = command_entry.get() or command_dropdown.get()
- if command:
- try:
- os.system(command)
- except Exception as e:
- messagebox.showerror("Error", str(e))
- # GUI setup
- root = tk.Tk()
- root.title("Najeeb File Folder Explorer and Command Runner")
- root.geometry("900x640")
- root.configure(bg="#FFD700") # Set background color of the window
- # Load folder paths from FOLDERS.txt file
- folders = load_folders()
- # Load commands from Commands.txt file
- commands = load_commands()
- # Frame for the search field and button
- search_frame = tk.Frame(root)
- search_frame.pack(pady=10)
- # Search entry (top search result text field)
- search_entry = tk.Entry(search_frame, font=("Arial", 12), bg="white", fg="black", width=68)
- search_entry.pack(side=tk.LEFT, padx=5)
- # Search button
- search_button = tk.Button(search_frame, font=("Arial", 12), bg="blue", fg="white", text="Search", command=search_items)
- search_button.pack(side=tk.LEFT)
- # Frame to hold the Listbox and Scrollbars
- listbox_frame = tk.Frame(root)
- listbox_frame.pack(pady=10)
- # Listbox to show folder contents (editable)
- listbox = tk.Listbox(listbox_frame, selectmode=tk.SINGLE, font=("Arial", 12), bg="blue", fg="white", width=96, height=15)
- listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- # Vertical scrollbar
- v_scrollbar = tk.Scrollbar(listbox_frame, orient=tk.VERTICAL, command=listbox.yview)
- v_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- # Configuring Listbox scrollbars
- listbox.config(yscrollcommand=v_scrollbar.set)
- # Frame for the second result text field
- result_frame2 = tk.Frame(root)
- result_frame2.pack(pady=5)
- # Second text field (for opening .txt files on double-click)
- second_result_text = tk.Text(result_frame2, font=("Arial", 12), bg="white", fg="black", height=12, width=96)
- second_result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- # Vertical scrollbar for the second result text field
- result_scrollbar2 = tk.Scrollbar(result_frame2, orient=tk.VERTICAL, command=second_result_text.yview)
- result_scrollbar2.pack(side=tk.RIGHT, fill=tk.Y)
- # Configuring the text field scrollbar
- second_result_text.config(yscrollcommand=result_scrollbar2.set)
- # Bind double-click event to open the selected file in the second text field
- listbox.bind("<Double-1>", open_selected)
- # Frame for Run field and button
- run_frame = tk.Frame(root)
- run_frame.pack(pady=5)
- # Dropdown list for commands from Commands.txt
- command_dropdown = ttk.Combobox(run_frame, font=("Times New Roman", 16), values=commands, width=45)
- command_dropdown.pack(side=tk.LEFT, padx=5)
- # Command entry (Run field)
- command_entry = tk.Entry(run_frame, font=("Times New Roman", 16), bg="green", fg="white", width=20)
- command_entry.pack(side=tk.LEFT, padx=5)
- # Run button on the same line as the Run field and dropdown
- run_button = tk.Button(run_frame, font=("Arial", 12), bg="blue", fg="white", text="Run commands", command=run_command)
- run_button.pack(side=tk.LEFT, padx=5)
- # Load folder contents on startup
- list_items()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement