Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- import tkinter as tk
- from tkinter import messagebox, ttk
- from ttkthemes import ThemedTk
- def list_ahk_files(directory):
- """List all .ahk files in the specified directory."""
- try:
- return [f for f in os.listdir(directory) if f.endswith('.ahk')]
- except Exception as e:
- messagebox.showerror("Error", f"Failed to list files in directory: {e}")
- return []
- def open_ahk_file(filename):
- """Open the selected .ahk file using AutoHotkey."""
- try:
- subprocess.Popen(['start', '', filename], shell=True)
- except Exception as e:
- messagebox.showerror("Error", f"Failed to open file: {e}")
- def on_file_select(event):
- """Event handler for file selection."""
- selected_index = file_listbox.curselection()
- if selected_index:
- selected_file = file_listbox.get(selected_index)
- open_ahk_file(os.path.join(folder_path, selected_file))
- # Specify the folder containing .ahk files
- folder_path = 'C:/CMDER/TOOLS'
- # List all .ahk files in the folder
- ahk_files = list_ahk_files(folder_path)
- # Create the main window with a theme
- root = ThemedTk(theme="arc")
- root.title("Select an .ahk File to Open")
- # Create a frame for better layout control
- frame = ttk.Frame(root, padding="10")
- frame.pack(fill=tk.BOTH, expand=True)
- # Create a Listbox to display the .ahk files
- file_listbox = tk.Listbox(frame, selectmode=tk.SINGLE, height=15)
- for file in ahk_files:
- file_listbox.insert(tk.END, file)
- file_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(0, 5))
- # Create a scrollbar for the Listbox
- scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL, command=file_listbox.yview)
- scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- file_listbox.config(yscrollcommand=scrollbar.set)
- # Bind the selection event to the handler
- file_listbox.bind('<<ListboxSelect>>', on_file_select)
- # Start the GUI event loop
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement