SHARE
    TWEET
    Najeebsk

    Run.pyw

    Aug 27th, 2024 (edited)
    313
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 5.22 KB | None | 0 0
    1. import os
    2. import tkinter as tk
    3. from tkinter import messagebox, ttk
    4. def load_folders():
    5. folders = []
    6. try:
    7. with open('FOLDERS.txt', 'r', encoding='utf-8', errors='replace') as file:
    8. folders = [line.strip() for line in file if line.strip()]
    9. except FileNotFoundError:
    10. messagebox.showerror("Error", "FOLDERS.txt file not found.")
    11. return folders
    12. def load_commands():
    13. commands = []
    14. try:
    15. with open('Commands.txt', 'r', encoding='utf-8', errors='replace') as file:
    16. commands = [line.strip() for line in file if line.strip()]
    17. except FileNotFoundError:
    18. messagebox.showerror("Error", "Commands.txt file not found.")
    19. return commands
    20. def list_items(search_term=None):
    21. listbox.delete(0, tk.END)
    22. for folder in folders:
    23. if os.path.exists(folder):
    24. for item in os.listdir(folder):
    25. if not search_term or search_term.lower() in item.lower():
    26. listbox.insert(tk.END, item)
    27. else:
    28. messagebox.showerror("Error", f"Folder not found: {folder}")
    29. def search_items():
    30. search_term = search_entry.get()
    31. list_items(search_term)
    32. def open_selected(event=None):
    33. selected = listbox.get(tk.ACTIVE)
    34. if selected:
    35. for folder in folders:
    36. full_path = os.path.join(folder, selected)
    37. if os.path.exists(full_path):
    38. # Check if the selected file has an allowed extension
    39. if selected.endswith(('.txt', '.py', '.pyw', '.ahk', '.bat', '.m3u', '.m3u8', '.reg', '.vbs', '.ls')):
    40. try:
    41. with open(full_path, 'r', encoding='utf-8', errors='replace') as file:
    42. second_result_text.delete(1.0, tk.END)
    43. second_result_text.insert(tk.END, file.read())
    44. second_result_text.config(state=tk.NORMAL) # Ensure the second result_text field is editable
    45. except Exception as e:
    46. messagebox.showerror("Error", str(e))
    47. else:
    48. os.startfile(full_path)
    49. break
    50. def run_command():
    51. command = command_entry.get() or command_dropdown.get()
    52. if command:
    53. try:
    54. os.system(command)
    55. except Exception as e:
    56. messagebox.showerror("Error", str(e))
    57. # GUI setup
    58. root = tk.Tk()
    59. root.title("Najeeb File Folder Explorer and Command Runner")
    60. root.geometry("900x640")
    61. root.configure(bg="#FFD700") # Set background color of the window
    62. # Load folder paths from FOLDERS.txt file
    63. folders = load_folders()
    64. # Load commands from Commands.txt file
    65. commands = load_commands()
    66. # Frame for the search field and button
    67. search_frame = tk.Frame(root)
    68. search_frame.pack(pady=10)
    69. # Search entry (top search result text field)
    70. search_entry = tk.Entry(search_frame, font=("Arial", 12), bg="white", fg="black", width=68)
    71. search_entry.pack(side=tk.LEFT, padx=5)
    72. # Search button
    73. search_button = tk.Button(search_frame, font=("Arial", 12), bg="blue", fg="white", text="Search", command=search_items)
    74. search_button.pack(side=tk.LEFT)
    75. # Frame to hold the Listbox and Scrollbars
    76. listbox_frame = tk.Frame(root)
    77. listbox_frame.pack(pady=10)
    78. # Listbox to show folder contents (editable)
    79. listbox = tk.Listbox(listbox_frame, selectmode=tk.SINGLE, font=("Arial", 12), bg="blue", fg="white", width=96, height=15)
    80. listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    81. # Vertical scrollbar
    82. v_scrollbar = tk.Scrollbar(listbox_frame, orient=tk.VERTICAL, command=listbox.yview)
    83. v_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
    84. # Configuring Listbox scrollbars
    85. listbox.config(yscrollcommand=v_scrollbar.set)
    86. # Frame for the second result text field
    87. result_frame2 = tk.Frame(root)
    88. result_frame2.pack(pady=5)
    89. # Second text field (for opening .txt files on double-click)
    90. second_result_text = tk.Text(result_frame2, font=("Arial", 12), bg="white", fg="black", height=12, width=96)
    91. second_result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    92. # Vertical scrollbar for the second result text field
    93. result_scrollbar2 = tk.Scrollbar(result_frame2, orient=tk.VERTICAL, command=second_result_text.yview)
    94. result_scrollbar2.pack(side=tk.RIGHT, fill=tk.Y)
    95. # Configuring the text field scrollbar
    96. second_result_text.config(yscrollcommand=result_scrollbar2.set)
    97. # Bind double-click event to open the selected file in the second text field
    98. listbox.bind("<Double-1>", open_selected)
    99. # Frame for Run field and button
    100. run_frame = tk.Frame(root)
    101. run_frame.pack(pady=5)
    102. # Dropdown list for commands from Commands.txt
    103. command_dropdown = ttk.Combobox(run_frame, font=("Times New Roman", 16), values=commands, width=45)
    104. command_dropdown.pack(side=tk.LEFT, padx=5)
    105. # Command entry (Run field)
    106. command_entry = tk.Entry(run_frame, font=("Times New Roman", 16), bg="green", fg="white", width=20)
    107. command_entry.pack(side=tk.LEFT, padx=5)
    108. # Run button on the same line as the Run field and dropdown
    109. run_button = tk.Button(run_frame, font=("Arial", 12), bg="blue", fg="white", text="Run commands", command=run_command)
    110. run_button.pack(side=tk.LEFT, padx=5)
    111. # Load folder contents on startup
    112. list_items()
    113. root.mainloop()
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /