Advertisement
Najeebsk

T-MENU2.pyw

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