[Tkinter] Show temperature in gui - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Show temperature in gui (/thread-7574.html) Pages:
1
2
|
RE: Show temperature in gui - katastroooof - Jan-18-2018 YOU my friend, are a magician ! Thank you so much for your help. RE: Show temperature in gui - katastroooof - Jan-19-2018 Ok, so now my GUI is running very nicely when started from Python3 shell. There is one error message: Traceback (most recent call last): File "FRAMO.py", line 192, in <module> app = Application(root) File "FRAMO.py", line 28, in __init__ self.start() TypeError: 'NoneType' object is not callable When trying to start from terminal I get the same error message but the GUI doesn't run. I'm trying to get it to boot at startup , could this error be the reason why it doesn't? Here's my current code: #!/usr/bin/python from tkinter import * import tkinter as tk from max31855 import MAX31855, MAX31855Error import time UPDATE_RATE = 2000 UPDATE_RATE1 = 10000 global Running Running = False class Application(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master) self.grid self.create_widgets() self.updater() self.updater1() self.start() self.stop() def create_widgets(self): #FRAMO LOGO self.label=tk.Label(self.master, image=logo) self.label.columnconfigure(0, weight=1) self.label.rowconfigure(0, weight=1) self.label.grid(row=0, column=3) #TEMPERATURER self.label1=tk.Label(self.master,text='Initial value', fg='blue', font=("Arial", 36, "bold"), background='#CDC5D9') self.label1.columnconfigure(0, weight=1) self.label1.rowconfigure(0, weight=1) self.label1.grid(row=0, column=1) #NAVN PÅ SENSORER self.label2=tk.Label(self.master,text='Sensor1\nSensor2\nSensor3\nSensor4\nSensor5\nSensor6', fg='blue', font=("Arial", 36, "bold"), background='#CDC5D9') self.label2.columnconfigure(0, weight=1) self.label2.rowconfigure(0, weight=1) self.label2.grid(row=0, column=2) #STATUS self.label3=tk.Label(self.master,text='Status', fg='blue', font=("Arial", 20, "bold"), background='#CDC5D9') self.label3.columnconfigure(0, weight=1) self.label3.rowconfigure(0, weight=1) self.label3.grid(row=2, column=2) #START KNAPP self.start=tk.Button(self.master, text="START", command=self.start, bg="green", font=("Arial", 48, "bold")).grid(row=1, column=1) #STOPP KNAPP self.stop=tk.Button(self.master, text="STOPP", command=self.stop, bg="yellow", font=("Arial", 48, "bold")).grid(row=1, column=2) #AVSLUTT self.end=tk.Button(self.master, text="SLÅ AV", command=self.end, bg="red", font=("Arial", 48, "bold")).grid(row=1, column=3) def end(self): from subprocess import call call ("sudo poweroff", shell=True) def start(self): # enable logging # self.label3['text'] = "Logging startet" self.label3["fg"] = "green" f = open('/media/pi/KINGSTON/LOGG', 'a') print (f.write("-------------------------------\n")) print (f.write("Logging har startet\n")) print (f.write("\n")) print (f.write(time.strftime("%H:%M:%S\n"))) print (f.write(time.strftime("%d/%m/%Y\n"))) print (f.write("-------------------------------\n")) global Running Running = True def stop(self): self.label3['text'] = "Logging ferdig" self.label3["fg"] = "red" # Disable logging # f = open('/media/pi/KINGSTON/LOGG', 'a') print (f.write("-------------------------------\n")) print (f.write("Logging avsluttet\n")) print (f.write("\n")) print (f.write(time.strftime("%H:%M:%S\n"))) print (f.write(time.strftime("%d/%m/%Y\n"))) global Running Running = False def updater(self): ## SKRIV TIL GUI ## self.after(UPDATE_RATE, self.updater) cs_pins = [25, 8, 7, 5, 6, 12] clock_pin = 11 data_pin = 9 units = "c" thermocouples = [] for cs_pin in cs_pins: thermocouples.append(MAX31855(cs_pin, clock_pin, data_pin, units)) meh = True if (meh): try: acc = [] for thermocouple in thermocouples: rj = thermocouple.get_rj() try: tc = thermocouple.get() except MAX31855Error as e: tc = "Error: "+ e.value meh = False acc.append(tc) self.label1['text'] = ' {} '.format('\n '.join(str(x) for x in acc)) self.label1["fg"] = "green" except KeyboardInterrupt: meh = False for thermocouple in thermocouples: thermocouple.cleanup() def updater1(self): ## SKRIV TIL USB ## self.after(UPDATE_RATE1, self.updater1) f = open('/media/pi/KINGSTON/LOGG', 'a') if Running: cs_pins = [25, 8, 7, 5, 6, 12] clock_pin = 11 data_pin = 9 units = "c" thermocouples = [] for cs_pin in cs_pins: thermocouples.append(MAX31855(cs_pin, clock_pin, data_pin, units)) meh = True if (meh): try: for thermocouple in thermocouples: rj = thermocouple.get_rj() try: tc = thermocouple.get() except MAX31855Error as e: tc = "Error: "+ e.value meh = False print (f.write("Sensor: {} *C".format(tc))), (f.write(" kl. ")), (f.write(time.strftime("%H:%M:%S\n"))) except KeyboardInterrupt: meh = False for thermocouple in thermocouples: thermocouple.cleanup() root = tk.Tk() logo = tk.PhotoImage(file="logo.gif") root.title("VIRK DIN SATAN") root.attributes('-fullscreen', True) app = Application(root) app.grid() self.root.columnconfigure(0, weight=1) self.root.rowconfigure(0, weight=1) self.root = root root.geometry("700x700") root.mainloop RE: Show temperature in gui - Gribouillis - Jan-19-2018 (Jan-19-2018, 11:33 AM)katastroooof Wrote: There is one error message:In create_widgets() you define members self.start, self.stop etc . They shadow the methods start(), stop() , so that python can no longer call the method self.start() because self.start is a Button. The solution is to change the names of the said members. You can call them self.start_btn etc.
RE: Show temperature in gui - katastroooof - Jan-23-2018 Thanks, so now that is fixed. When running python3 filename.py in terminal , the GUI does not appear, only executing commands. Any good ideas on how to run at boot? RE: Show temperature in gui - Gribouillis - Jan-23-2018 Did you write root.mainloop()with parentheses at the end of the file? In order to run at boot, it depends on your OS. RE: Show temperature in gui - katastroooof - Jan-23-2018 Indeed, that helped. Im running Raspbian , Debian Jessie Tried with rc.local and systemctl but none of them were succesfull. rc.local is working but not at boot. RE: Show temperature in gui - Gribouillis - Jan-23-2018 (Jan-23-2018, 01:47 PM)katastroooof Wrote: Im running Raspbian , Debian JessieDid you try one of the online tutorials, such as this one? Perhaps the systemd approach, or simply crontab? RE: Show temperature in gui - katastroooof - Jan-26-2018 After trying with systemd approach and crontab and simply failing, (when booting to CLI i got tk.tkinter.tclerror no display name and no $display enviorment root =tk.Tk() - tried various things to fix that but...) I ended up with this: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart added @sh /home/pi/startup.sh Created the startup file: sudo nano /home/pi/startup.sh Wrote in file: #!/usr/bin/sh sleep 4 python3 /home/pi/name_of_app.py Saved it. Made it executable: sudo chmod +x /home/pi/startup.sh Now its starting 4 seconds after booting to desktop. |