Jan-23-2022, 06:49 PM
ok deanhystad, here is my newest code that I slapped together... it is messy and I know that already. It does work, and it does tell me what the current state is of the relay and starts the window with button state ON or OFF based on the status.
from tkinter import * from tkinter import messagebox import requests import time import os import json ws = Tk() ws.title('Relay Control') ws.geometry("600x400") ws.configure(background='white') on = PhotoImage(file = "frPorch_on.png") off = PhotoImage(file = "frPorch_off.png") shelly01 = 'http://shelly1-483fda82683f/status' shURL = 'NOT_INIT' shURL = shelly01 sh01 = requests.get(shURL) x = json.loads(sh01.text) status = x["relays"] a = status is_on = a[0]['ison'] print(is_on) def Switch(): global is_on if is_on: button.config(image = off) label.config(text = "Switch is Off", fg = "grey", bg='white') requests.post('http://shelly1-483fda82683f/relay/0/?turn=off') is_on = False else: button.config(image = on) label.config(text = "Switch is On", fg = "green", bg='white') requests.post('http://shelly1-483fda82683f/relay/0/?turn=on') is_on = True if is_on == True: button = Button(ws, image = on, bg='white', bd = 0, command = Switch) button.pack(pady = 30) label = Label(ws, text = "The Switch Is On!", bg='white', fg = "green", font = ("Helvetica", 32)) label.pack(pady = 20) else: button = Button(ws, image = off, bg='white', bd = 0, command = Switch) button.pack(pady = 30) label = Label(ws, text = "The Switch Is Off!", bg='white', fg = "grey", font = ("Helvetica", 32)) label.pack(pady = 20) ws.mainloop()