-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spiral.py
63 lines (45 loc) · 2.43 KB
/
Spiral.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import tkinter as tk
from tkinter import messagebox
import subprocess
def Spirals():
# Function to execute the selected algorithm
# Create the main Tkinter window
window = tk.Toplevel(height=0 , width=0, bg="#263d42",cursor="circle", borderwidth=0)
window.title("MECHANICUS_V.0.1 Beta. (c)Reservoir Frogs 2022")
window.configure(bg="#263d42", borderwidth=0)
def run_algorithm(filename):
try:
subprocess.run(["python", filename])
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {str(e)}")
# Function to load Python files from the "mosaic" folder
def load_python_files():
folder_path = "mosaic" # Change this to your folder path
if not os.path.exists(folder_path):
messagebox.showerror("Error", f"The 'mosaic' folder does not exist.")
return
python_files = [f for f in os.listdir(folder_path) if f.endswith(".py")]
if not python_files:
messagebox.showinfo("Info", "No Python files found in the 'mosaic' folder.")
button_frame = tk.Frame(window, bg="#263d42") # Create a frame for buttons
button_frame.pack()
buttons_per_row = 3 # Number of buttons per row
current_row = [] # Track buttons in the current row
for file in python_files:
algo_name = os.path.splitext(file)[0]
# Create a button for each algorithm with the desired background and text color
algo_button = tk.Button(button_frame, text=algo_name, command=lambda file=file: run_algorithm(os.path.join(folder_path, file)), bg="#263d42", fg="white", width=40)
current_row.append(algo_button)
if len(current_row) == buttons_per_row:
# If the current row is full, create a new row
for button in current_row:
button.grid(row=len(button_frame.grid_slaves()) // buttons_per_row, column=len(button_frame.grid_slaves()) % buttons_per_row)
current_row = []
# Place any remaining buttons in the last row
for button in current_row:
button.grid(row=len(button_frame.grid_slaves()) // buttons_per_row, column=len(button_frame.grid_slaves()) % buttons_per_row)
# Load Python files and create buttons
load_python_files()
# Start the main event loop
window.mainloop()