Basic gpio app btns

#!/home/user_name/project/venv/bin/python3.11

import tkinter as tk
import RPi.GPIO as GPIO

# Setup GPIO
GPIO.setmode(GPIO.BCM)  # Use BCM pin numbering
GPIO.setup(24, GPIO.OUT)  # Set GPIO pin 24 as output
GPIO.setup(18, GPIO.OUT)  # Set GPIO pin 18 as output

# Default state for the pins
GPIO.output(24, GPIO.LOW)  # Set GPIO 24 to LOW (off)
GPIO.output(18, GPIO.LOW)  # Set GPIO 18 to LOW (off)

# Function to handle the LED on GPIO 24
def toggle_led1():
    if GPIO.input(24):  # Check if LED is on
        GPIO.output(24, GPIO.LOW)  # Turn it off
        btn1["text"] = "LED1 OFF"  # Change button text
    else:
        GPIO.output(24, GPIO.HIGH)  # Turn it on
        btn1["text"] = "LED1 ON"  # Change button text

# Function to handle the LED on GPIO 18
def toggle_led2():
    if GPIO.input(18):  # Check if LED is on
        GPIO.output(18, GPIO.LOW)  # Turn it off
        btn2["text"] = "LED2 OFF"  # Change button text
    else:
        GPIO.output(18, GPIO.HIGH)  # Turn it on
        btn2["text"] = "LED2 ON"  # Change button text

# Function to clean up GPIO and close the app
def close():
    GPIO.cleanup()  # Reset the GPIO pins
    root.destroy()  # Close the GUI

def create_app():
    global root
    root = tk.Tk()
    root.title("GPIO Control")
    root.geometry('400x300')  # Set window size
    root.configure(bg="black")

    label = tk.Label(root, text="GPIO Control Panel", fg="white", bg="black", font=("Helvetica", 16))
    label.pack(pady=20)

    global btn1
    btn1 = tk.Button(root, text="LED1 OFF", font=("Helvetica", 16), command=toggle_led1, width=15, height=2, bg="#003333", fg="green", activeforeground="white", activebackground="black")
    btn1.pack(pady=10)

    global btn2
    btn2 = tk.Button(root, text="LED2 OFF", font=("Helvetica", 16), command=toggle_led2, width=15, height=2, bg="#003333", fg="green", activeforeground="white", activebackground="black")
    btn2.pack(pady=10)

    # Close button
    close_button = tk.Button(root, text="Close", font=("Helvetica", 16), command=close, width=15, height=2, bg="#990000", fg="white", activeforeground="white", activebackground="black")
    close_button.pack(pady=20)

    root.mainloop()  # Start the Tkinter main loop

if __name__ == "__main__":
    create_app()