#!/home/user_name/project/venv/bin/python3.11
import tkinter as tk
from PIL import Image, ImageTk
import RPi.GPIO as GPIO
# Setup GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.OUT)
GPIO.output(24, GPIO.HIGH)
# Create the main window
root = tk.Tk()
root.title("toggle gpio pins and Swap Image")
root.geometry("300x300")
# Load images using Pillow
image1 = Image.open("/path/to/folder/img/button1.png") # Image for 'Initial'
image1 = ImageTk.PhotoImage(image1)
image2 = Image.open("/path/to/folder/img/button2.png") # Image for 'Clicked'
image2 = ImageTk.PhotoImage(image2)
# Function to open webpage and swap images
def led1():
print("LED button pressed")
if GPIO.input(24):
GPIO.output(24, GPIO.LOW)
btn.config(image=image1, text="off")
else:
GPIO.output(24, GPIO.HIGH)
btn.config(image=image2, text="on")
# Create the button with the initial image and command
btn = tk.Button(root, image=image1, text="Click to Open", compound="top", command=led1)
btn.pack(pady=50)
# Run the GUI loop
root.mainloop()