хорошо, поигравшись, мне удалось получить ответ, чтобы обойти это с помощью следующего кода. единственная проблема, которую я вижу, это когда я нажимаю кнопку подачи, программа вызывает 20-минутную остановку на выводах GPIO. поэтому он не будет обновлять метки во время этого перерыва. но надеюсь, что это поможет людям найти способы сделать это
import tkinter as tk
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#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
ftlab= 'Verdana', 13, 'bold'
ftb= 'Verdana', 11, 'bold'
#setup tkinter
def rtn1auto():
GPIO.output(2, GPIO.HIGH)
def rtn1off():
GPIO.output(2, GPIO.LOW)
def rtn2on():
GPIO.output(3, GPIO.HIGH)
def rtn2off():
GPIO.output(3, GPIO.LOW)
def pwrhd1on():
GPIO.output(11, GPIO.HIGH)
def pwrhd1off():
GPIO.output(11, GPIO.LOW)
def pwrhd2on():
GPIO.output(9, GPIO.HIGH)
def pwrhd2off():
GPIO.output(9, GPIO.LOW)
def gyreon():
GPIO.output(4, GPIO.HIGH)
def gyreoff():
GPIO.output(4, GPIO.LOW)
def rtn1feed():
time.sleep(15)
GPIO.output(2, GPIO.LOW)
time.sleep(3)
GPIO.output(3, GPIO.LOW)
time.sleep(3)
GPIO.output(4, GPIO.LOW)
time.sleep(3)
GPIO.output(11, GPIO.LOW)
time.sleep(3)
GPIO.output(9, GPIO.LOW)
time.sleep(1200)
GPIO.output(2, GPIO.HIGH)
time.sleep(3)
GPIO.output(3, GPIO.HIGH)
time.sleep(3)
GPIO.output(4, GPIO.HIGH)
time.sleep(3)
GPIO.output(11, GPIO.HIGH)
time.sleep(3)
GPIO.output(9, GPIO.HIGH)
class gpio(tk.Tk):
def __init__(root, *args, **kwargs):
tk.Tk.__init__(root, *args, **kwargs)
root.title("johns")
root.geometry("800x550")
root.configure(bg="lightblue")
#setup exit button
Exitbutton= tk.Button(root, text="Exit", font=(ftb), width=6, bg="red", fg="white", command=root.destroy)
Exitbutton.place(x=700, y=240)
#setup image
#photo1 = tk.PhotoImage(file="fish.gif") #defines a photo and gives the file name
#label1 = tk.Label(root, image=photo1)#puts label in the window in this case not text file must be in program folder
#label1.place(x=0, y=0) #says how to place the label
#set up return pump 1 buttons and labels
root.rtnp1label = tk.Label(root, text="")
root.rtnp1label.place(x=560, y=300)
labelreturn1= tk.Label(root, text=("RETURN PUMP 1"), font=(ftlab), bg="yellow", fg="black")
labelreturn1.place(x=0, y=300)
butreturn1auto= tk.Button(root, text=("AUTO RUN"), font=(ftb), command=rtn1auto)
butreturn1auto.place(x=180, y=296)
butreturn1off= tk.Button(root, text=("PUMP OFF"), font=(ftb), command=rtn1off)
butreturn1off.place(x= 300, y=296)
labelreturn1gpio= tk.Label(root, text=("GPIO 2"), font=(ftlab), bg="black", fg="white")
labelreturn1gpio.place(x= 670, y=300)
#setup return pump 2 buttons and labels
root.rtnp2label = tk.Label(root, text="")
root.rtnp2label.place(x=560, y=335)
labelreturn2= tk.Label(root, text=("RETURN PUMP 2"), font=(ftlab), bg="yellow", fg="black")
labelreturn2.place(x=0, y=335)
butreturn2on= tk.Button(root, text=("PUMP ON"), font=(ftb), command=rtn2on)
butreturn2on.place(x=180, y=331)
butreturn2off= tk.Button(root, text=("PUMP OFF"), font=(ftb), command=rtn2off)
butreturn2off.place(x= 300, y= 331)
labelreturn2gpio= tk.Label(root, text=("GPIO 3"), font=(ftlab), bg="black", fg="white")
labelreturn2gpio.place(x= 670, y=335)
#setup powerhead 2 buttons and labels
root.pwrhd2label = tk.Label(root, text="")
root.pwrhd2label.place(x=560, y=496)
labelpwrhd2= tk.Label(root, text=("POWER HEAD 2"), font=(ftlab), bg="orange", fg="black")
labelpwrhd2.place(x=0, y=496)
butpwrhd2= tk.Button(root, text=("PUMP ON"), font=(ftb), command=pwrhd2on)
butpwrhd2.place(x=180, y=492)
butpwrhd2= tk.Button(root, text=("PUMP OFF"), font=(ftb), command=pwrhd2off)
butpwrhd2.place(x= 300, y= 492)
labelpwrhd2gpio= tk.Label(root, text=("GPIO 9"), font=(ftlab), bg="black", fg="white")
labelpwrhd2gpio.place(x= 670, y=496)
#setup powerhead 1 buttons and lbels
root.pwrhd1label = tk.Label(root, text="")
root.pwrhd1label.place(x=560, y=450)
labelpwrhd1= tk.Label(root, text=("POWER HEAD 1"), font=(ftlab), bg="orange", fg="black")
labelpwrhd1.place(x=0, y=450)
butpwrhd1= tk.Button(root, text=("PUMP ON"), font=(ftb), command=pwrhd1on)
butpwrhd1.place(x=180, y=446)
butpwrhd1= tk.Button(root, text=("PUMP OFF"), font=(ftb), command=pwrhd1off)
butpwrhd1.place(x= 300, y= 446)
labelpwrhd1gpio= tk.Label(root, text=("GPIO 11"), font=(ftlab), bg="black", fg="white")
labelpwrhd1gpio.place(x= 670, y=450)
#setup gyre pump buttons and labels
root.gyrelabel =tk.Label(root, text="")
root.gyrelabel.place(x=560, y=400)
labelgyre= tk.Label(root, text=("GYRE WAVE "), font=(ftlab), bg="green", fg="black")
labelgyre.place(x=0, y=400)
butgyreon= tk.Button(root, text=("PUMP ON"), font=(ftb), command=gyreon)
butgyreon.place(x=180, y=396)
butgyreoff= tk.Button(root, text=("PUMP OFF"), font=(ftb), command=gyreoff)
butgyreoff.place(x= 300, y= 396)
labelgyregpio= tk.Label(root, text=("GPIO 4"), font=(ftlab), bg="black", fg="white")
labelgyregpio.place(x= 670, y=400)
#setup feed button
butreturn1feed= tk.Button(root, text=("20 MINUTE ") + ("FEED TIMER"),wraplength=90, font=(ftb),bg="red",
height=12, command=rtn1feed)
butreturn1feed.place(x= 420, y=296)
# start the GPIO checks"
root.update_gpio()
def update_gpio(root):
rt1 = (' On ' if GPIO.input(2) else ' Off ')
root.rtnp1label.configure(text=rt1, bg ="yellow", font=(ftb))
rt2 = (' On ' if GPIO.input(3) else ' Off ')
root.rtnp2label.configure(text=rt2, bg ="yellow", font=(ftb))
ph2 = (' On ' if GPIO.input(9) else ' Off ')
root.pwrhd2label.configure(text=ph2, bg ="yellow", font=(ftb))
ph1 = (' On ' if GPIO.input(11) else ' Off ')
root.pwrhd1label.configure(text=ph1, bg ="yellow", font=(ftb))
gyr = (' On ' if GPIO.input(4) else ' Off ')
root.gyrelabel.configure(text=gyr, bg ="yellow", font=(ftb))
# call this function again in one second
root.after(200, root.update_gpio)
if __name__== "__main__":
app = gpio()
app.mainloop()