So I'm making a script for a raspberry pi 3-b. The idea is to take sensor readings from 4 sensors, and display each reading, updating over time, in each corner overtop of a background image. I am mostly unfamiliar with python, and new to tkinter.
The following is my current code.
from tkinter import *
from PIL import ImageTk
import Adafruit_DHT
import tkinter as tk
from tkinter import font as tkfont
window = Tk()
def main():
c = Canvas(window,height=480,width=800)
image = ImageTk.PhotoImage(file="/home/pi/Desktop/AppFiles/AppBackround.jpg")
c.create_image(0,0,image=image,anchor=NW)
text1 = tk.StringVar()
text2 = tk.StringVar()
text3 = tk.StringVar()
text4 = tk.StringVar()
myFont = tkfont.Font(family="Titillium Web", size=32)
c.create_text(10,10,text=text1,fill="yellow",font=myFont)
c.create_text(10,450,text=text2,fill="yellow",font=myFont)
c.create_text(750,10,text=text3,fill="yellow",font=myFont)
c.create_text(750,450,text=text4,fill="yellow",font=myFont)
c.pack()
def update():
sensor = Adafruit_DHT.DHT22
DHT22_pin1 = 4
DHT22_pin2 = 17
DHT22_pin3 = 27
DHT22_pin4 = 22
humidity1, temperature1 = Adafruit_DHT.read_retry(sensor, DHT22_pin1)
humidity2, temperature2 = Adafruit_DHT.read_retry(sensor, DHT22_pin2)
humidity3, temperature3 = Adafruit_DHT.read_retry(sensor, DHT22_pin3)
humidity4, temperature4 = Adafruit_DHT.read_retry(sensor, DHT22_pin4)
text="Temperature1={0:0.1f}*C Humidity1={1:0.1f}%".format(temperature1, humidity1)
text="Temperature2={0:0.1f}*C Humidity2={1:0.1f}%".format(temperature2, humidity2)
text="Temperature3={0:0.1f}*C Humidity3={1:0.1f}%".format(temperature3, humidity3)
text="Temperature4={0:0.1f}*C Humidity4={1:0.1f}%".format(temperature4, humidity4)
window.after(100, update)
main()
update()
window.mainloop()
For some reason, my image is displaying as a blank gray background and my text is not displaying the readings or updating. instead I get this
What am I doing wrong, can anyone please explain what is going wrong here and how I might fix it?