i am trying to use an image inside a label to show a change in the gpio state, i have been able to use text to change but now would like to use a picture of and led and a fish image. but i cant get it to find the image.
import tkinter as tk
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#Setup input GPIO pins for use with optical infrared sensors
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) # SUMP LOW WATER LEVEL SENSOR
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) # SUMP NORM WATER LEVEL SENSOR
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) # SUMP HIGH WATER LEVEL SENSOR
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP) # RO LOW WATER LEVEL SENSOR
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP) # DISPLAY HIGH WATER LEVEL
#GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP) # MAY USE AS PROTIEN SKIMMER SENSOR
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) # DISPLAY LOW WATER LEVEL SENSOR
#setup output pins for relay control
GPIO.setup(2, GPIO.OUT) #return pump 1 ch 1 cutoff relay in series with GPIO(8)
GPIO.setup(3, GPIO.OUT) #return pump 2 ch 2 relay
GPIO.setup(4, GPIO.OUT) #gyre pump ch3 relay
GPIO.setup(8, GPIO.OUT) #used for return pump 1
GPIO.setup(9, GPIO.OUT) #power head 2 ch 5 relay
GPIO.setup(11, GPIO.OUT) #power head 1 ch
GPIO.setup(7, GPIO.OUT) # AUTO TOP OFF PUMP
#Setup output GPIO pins for use with Red Yellow and Green LEDS
GPIO.setup(23, GPIO.OUT) # DISPLAY HIGH WATER LEVEL RED LED
GPIO.setup(24, GPIO.OUT) # DISPLAY NORM WATER LEVEL GREEN LED
GPIO.setup(25, GPIO.OUT) # DISPLAY LOW WATER LEVEL YELLOW LED
GPIO.setup(12, GPIO.OUT) # AUTO TOP OFF LOW LEVEL RED LED
GPIO.setup(16, GPIO.OUT) # SUMP HIGH WATER LEVEL RED LED
GPIO.setup(20, GPIO.OUT) # SUMP NORMAL WATER LEVEL GREEN LED
GPIO.setup(21, GPIO.OUT) # SUMP LOW WATER LEVEL YELLOW LED
#setup fonts
ftb= 'Verdana', 12, 'bold'
def photo2():
photo2= oraled.png
#setup class for the tk program
class gpio(tk.Tk):
def __init__(root, *args, **kwargs):
tk.Tk.__init__(root, *args, **kwargs)
root.title("trial")
root.geometry("430x830")
root.configure(bg="lightblue")
#setup image
root.photo1 = tk.PhotoImage(file="fish.gif") #defines a photo and gives the file name
root.label1 = tk.Label(root, image=root.photo1)#puts label in the window in this case not text file must be in program folder
root.label1.place(x=0, y=0) #says how to place the label
#setup display high sensor label
root.photo2 = tk.PhotoImage(file='oraled.png')
root.dishisensorlabel= tk.Label(root, image="")
root.dishisensorlabel.place(x=210, y=500)
labeldishisensor= tk.Label(root,text=("Display High"), font=(ftb), fg="black")
labeldishisensor.place(x=0, y=500)
root.update_gpio()
def update_gpio(root):
dhsen =('fish.gif' if GPIO.input(5) else 'oraled')
root.dishisensorlabel.configure(image=dhsen)
root.after(200, root.update_gpio)
if __name__== "__main__":
app = gpio()
app.mainloop()
i get the following errors i am running this in thorney while i delevelop the script
>>> %Run 'use of images for leds.py'
Traceback (most recent call last):
File "/home/pi/use of images for leds.py", line 63, in <module>
app = gpio()
File "/home/pi/use of images for leds.py", line 55, in __init__
root.update_gpio()
File "/home/pi/use of images for leds.py", line 58, in update_gpio
root.dishisensorlabel.configure(image=dhsen)
File "/usr/lib/python3.7/tkinter/__init__.py", line 1485, in configure
return self._configure('configure', cnf, kw)
File "/usr/lib/python3.7/tkinter/__init__.py", line 1476, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "fish.gif" doesn't exist
>>>
any help would be appreciated