Ok, so I got it to show up finally. I think it must have been hiding behind the button (oops!). Now what I want to do is update the label info with the information sent back from the Sonoff switch. As you can see here, I put in a 'def getTemp()' and in 'def main()' I started with adding a button to get the request, which works. I would rather just have it update the label on open with that information and refresh every few minutes.
** I just edited the post here. I did get the clock to show up on the screen. Here is my complete code now. I just need to figure out the label updating for getting the temperature reading.
** I just edited the post here. I did get the clock to show up on the screen. Here is my complete code now. I just need to figure out the label updating for getting the temperature reading.
import tkinter as tk from tkinter import * from tkinter import messagebox import requests import http.client import time path = "" SONOFF_Temp = 'http://192.168.0.113/cm?cmnd=status+10' sonoff_url = 'NOT_INIT' class RelayButton(tk.Button): """A button that toggles a relay""" def __init__(self, parent, url="", on_image=None, off_image=None, **kwargs): super().__init__(parent, image=off_image, command=self.toggle) self.url = url self._on = False self.on_image = on_image self.off_image = off_image self.label = Label(text="", fg="Red", font=("Helvetica", 18)) self.label.place(x=600,y=20) self.update_clock() @property def on(self): """Return state of the relay""" return self._on @on.setter def on(self, on): """Set state of the relay""" self._on = on if on: requests.post(f"{self.url}cm?cmnd=Power On") self["image"] = self.on_image else: requests.post(f"{self.url}cm?cmnd=Power Off") self["image"] = self.off_image def toggle(self): """Toggle state of the relay""" self.on = not self.on def update_clock(self): now = time.strftime("%H:%M:%S") self.label.configure(text=now) self.after(1000, self.update_clock) def new_button(name, url, parent, row, column, **kwargs): """Convenience functon that creates a RelayButton""" on_image = tk.PhotoImage(file=f"{path}{name}_on.png") off_image = tk.PhotoImage(file=f"{path}{name}_off.png") button = RelayButton(parent, url, on_image, off_image, **kwargs) button.grid(row=row, column=column, padx=10, pady=10) return button def getTemp(): sonoff_url = SONOFF_Temp sonR1 = requests.get(sonoff_url) messagebox.showinfo("Temp", sonR1.text) def main(): app = tk.Tk() app.title('Home Relay Controls') tempbtn = Button(app, text='GET TEMP', command=getTemp) tempbtn.grid(row=1, column=2, padx=(250, 20)) buttons = [ new_button('living_room', "http://192.168.0.101/", app, 0, 0), new_button('front_porch', "http://192.168.0.113/", app, 0, 1) ] for b in buttons: b.on = False app.mainloop() if __name__ == "__main__": main()