Advertisement
Najeebsk

T-MENU.pyw

May 29th, 2024
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. import os
  2. import subprocess
  3. import tkinter as tk
  4. from tkinter import messagebox, ttk
  5. from ttkthemes import ThemedTk
  6.  
  7. def list_pyw_files(directory):
  8.     """List all .pyw files in the specified directory."""
  9.     return [f for f in os.listdir(directory) if f.endswith('.pyw')]
  10.  
  11. def open_pyw_file(filename):
  12.     """Open the selected .pyw file."""
  13.     try:
  14.         subprocess.Popen(['pythonw', filename], shell=True)
  15.     except Exception as e:
  16.         messagebox.showerror("Error", f"Failed to open file: {e}")
  17.  
  18. def on_file_select(event):
  19.     """Event handler for file selection."""
  20.     selected_index = file_listbox.curselection()
  21.     if selected_index:
  22.         selected_file = file_listbox.get(selected_index)
  23.         open_pyw_file(os.path.join(folder_path, selected_file))
  24.  
  25. # Specify the folder containing .pyw files
  26. folder_path = 'C:/CMDER/TOOLS'
  27.  
  28. # List all .pyw files in the folder
  29. pyw_files = list_pyw_files(folder_path)
  30.  
  31. # Create the main window with a theme
  32. root = ThemedTk(theme="arc")
  33. root.title("Najeeb Select a .pyw File to Open")
  34.  
  35. # Create a frame for better layout control
  36. frame = ttk.Frame(root, padding="10")
  37. frame.pack(fill=tk.BOTH, expand=True)
  38.  
  39. # Create a Listbox to display the .pyw files
  40. file_listbox = tk.Listbox(frame, selectmode=tk.SINGLE, height=15)
  41. for file in pyw_files:
  42.     file_listbox.insert(tk.END, file)
  43. file_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(0, 5))
  44.  
  45. # Create a scrollbar for the Listbox
  46. scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL, command=file_listbox.yview)
  47. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  48. file_listbox.config(yscrollcommand=scrollbar.set)
  49.  
  50. # Bind the selection event to the handler
  51. file_listbox.bind('<<ListboxSelect>>', on_file_select)
  52.  
  53. # Start the GUI event loop
  54. root.mainloop()
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement