29/10/2017, 10:55
Codice:
#Programma per lettura temperature
#importa librerie
from tkinter import*
import tkinter.font
import datetime
import Adafruit_DHT as dht
####################################################################################################################################################
###############################################################Crea visualizzazione grafica
win = Tk()
win.title ("Lettura Temperature Casa")
win.geometry ("550x390")
############################################################## definizione data e ora
def update_timeText():
current = datetime.datetime.now().strftime("Ore %H:%M:%S del %d/%m/%y")
timeText.configure(text=current)
win.after(1000, update_timeText)
timeText = Label(win, text="", fg="black", bg="white", font="10")
timeText.grid(row=0, column=2, sticky="w", padx=10, pady=10)
update_timeText()
############################################################## etichette fisse
the_label1 = Label (win, text="Temperatura Esterna = ", fg="black", bg="white", font="36")
the_label1.grid(row=2, column=0, sticky="w", padx=10, pady=10)
the_label2 = Label (win, text="Temperatura Sala = ", fg="black", bg="white", font="36")
the_label2.grid(row=4, column=0, sticky="w", padx=10, pady=10)
the_label3 = Label (win, text="Temperatura Bagno = ", fg="black", bg="white", font="36")
the_label3.grid(row=6, column=0, sticky="w", padx=10, pady=10)
the_label4 = Label (win, text="Temperatura Camera da letto = ", fg="black", bg="white", font="36")
the_label4.grid(row=8, column=0, sticky="w", padx=10, pady=10)
the_label5 = Label (win, text="Temperatura Cameretta = ", fg="black", bg="white", font="36")
the_label5.grid(row=10, column=0, sticky="w", padx=10, pady=10)
################################################################ etichette temperature .... eliminare 0° per provare la temperatura con dht
K= StringVar()
num=1
the_label1_1 = Label (win, text=K, fg="black", bg="white", font="36")
the_label1_1.grid(row=2, column=1, sticky="w", padx=10, pady=10)
the_label2_2 = Label (win, text="0° ", fg="black", bg="white", font="36")
the_label2_2.grid(row=4, column=1, sticky="w", padx=10, pady=10)
the_label3_3 = Label (win, text="0° ", fg="black", bg="white", font="36")
the_label3_3.grid(row=6, column=1, sticky="w", padx=10, pady=10)
the_label4_4 = Label (win, text="0° ", fg="black", bg="white", font="36")
the_label4_4.grid(row=8, column=1, sticky="w", padx=10, pady=10)
the_label5_5 = Label (win, text="0° ", fg="black", bg="white", font="36")
the_label5_5.grid(row=10, column=1, sticky="w", padx=10, pady=10)
def READ():
h,t = dht.read_retry(dht.DHT11, 4)
text = "Temp=%s*C Humidity=%s" %(t,h)
k.set(str(text))
# w = Label(win, text=newtext)
# w.pack()
mainloop()
ancora una volta vi chiedo aiuto per un piccolo programmino fatto in python che legge le temperature....
chiaro che e' un po scopiazatto.
Il problema e' inserire la temperatura letta dal sensore in un label di tkinter, ma sopratutto il problema piu' grosso e che mancandomi le basi faccio fatica e ci metto moltissimo tempo a relizzare cose che secondo me sono banali.
Sto leggendo alcuni testi ma sono ancora molto lontano e sopratutto mi sembrano complicatissimi. Grazie a tutti