So I'm trying to create a UI that allows multiple buttons in the same window. All of the are toggles to control GPIO outputs to control relays. I've managed to get them to all work individually in their own files, but when put into the same file is all on or all off. There is only 4 toggles for now, as a demonstration for my boss, but there will be many more on the final product.`
Below is the code I've come up with so far. (keep in mind I only started learning Python and coding in general yesterday) I'm on a bit of a time crunch and have used the search function. Thats the only way I've gotten this far. Thanks in Advance!!
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) try: import Tkinter as tk except ImportError: import tkinter as tk from Tkinter import * win=Tk() win.title("Q") def toggle(): if b1.config('text')[-1] == 'AMBIENT': b1.config(text='OFF') GPIO.setup(24, GPIO.OUT) GPIO.output(24, GPIO.LOW) else: b1.config(text='AMBIENT') GPIO.output(24, GPIO.HIGH) if b2.config('text')[-1] == 'CEILING': b2.config(text='OFF') GPIO.setup(18, GPIO.OUT) GPIO.output(18, GPIO.LOW) else: b2.config(text='CEILING') GPIO.output(18, GPIO.HIGH) b1 = Button(win, text="AMBIENT", command=toggle) b2 = Button(win, text="CEILING", command=toggle) b3 = Button(win, text="LASER", command=toggle) b4 = Button(win, text="RADIO", command=toggle) b1.pack(pady=2) b2.pack(pady=2) b3.pack(pady=2) b4.pack(pady=2) mainloop()