This code is part of a aquarium controller gui which i am work on. When this starts up it automatically displays the current state of the GPIO pins in label****state LABEL. What i am trying to do is find away of getting it to refresh the labels every 20 Seconds. i would prefer if this could be done with a button click.. iam not sure if this is possible or not.I am new to python so any help would be appreciated
import RPi.GPIO as GPIO
import time
import tkinter as tk
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
GPIO.setup(19, GPIO.OUT) #SPARE relay output
GPIO.setup(14, GPIO.OUT) #SPARE relay output
GPIO.setup(15, GPIO.OUT) #SPARE relay output
GPIO.setup(18, GPIO.OUT) #SPARE relay outlet
#set the outputs to high on startup
#GPIO.output(2, GPIO.HIGH) # return pump 1
#GPIO.output(3, GPIO.HIGH) # return pump 2
#GPIO.output(4, GPIO.HIGH) # gyre pump
#GPIO.output(9, GPIO.HIGH) # powerhead 2
#GPIO.output(11, GPIO.HIGH) # powerhead 1
#GPIO.output(19, GPIO.HIGH) # Spare
#GPIO.output(14, GPIO.HIGH) # Spare
#GPIO.output(15, GPIO.HIGH) # Spare
#GPIO.output(18, GPIO.HIGH) # Spare
time.sleep(1)
#setup tkinter
root=tk.Tk()
root.title("Johns Aquarium")
root.geometry("800x550")
root.configure(bg="lightblue")
#setup image
photo1 = tk.PhotoImage(file="fish.gif") #defines a photo and gives the file name
label1 = tk.Label(image=photo1)#puts label in the window in this case not text file must be in program folder
label1.grid(row=10, column=0, columnspan=12) #says how to place the label
#setup fonts
ftlab= 'Verdana', 13, 'bold'
ftb= 'Verdana', 11, 'bold'
#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 return pump 1
labelreturn1= tk.Label(root, text=("RETURN PUMP 1"), font=(ftlab), bg="yellow", fg="black")
labelreturn1.place(x=0, y=300)
labelreturn1gpio= tk.Label(root, text=("GPIO 2"), font=(ftlab), bg="black", fg="white")
labelreturn1gpio.place(x= 670, y=300)
labelreturn1state= tk.Label(root, font=(ftlab), fg="black")
labelreturn1state.place(x=550, y=296)
labelreturn1state.configure(text=' Auto ' if GPIO.input(2) else ' Off ')
#setup return pump 2
labelreturn2= tk.Label(root, text=("RETURN PUMP 2"), font=(ftlab), bg="yellow", fg="black")
labelreturn2.place(x=0, y=335)
labelreturn2gpio= tk.Label(root, text=("GPIO 3"), font=(ftlab), bg="black", fg="white")
labelreturn2gpio.place(x= 670, y=335)
labelreturn2state= tk.Label(root, font=(ftlab), fg="black")
labelreturn2state.place(x=550, y=331)
labelreturn2state.configure(text=' On ' if GPIO.input(3) else ' Off ')
#setup gyre pump buttons and labels
labelgyre= tk.Label(root, text=("GYRE WAVE "), font=(ftlab), bg="green", fg="black")
labelgyre.place(x=0, y=400)
labelgyregpio= tk.Label(root, text=("GPIO 4"), font=(ftlab), bg="black", fg="white")
labelgyregpio.place(x= 670, y=400)
labelgyrestate= tk.Label(root, font=(ftlab), fg="black")
labelgyrestate.place(x=550, y=396)
labelgyrestate.configure(text=' On ' if GPIO.input(4) else ' Off ')
#setup power head 1 pump
labelpwrhd1= tk.Label(root, text=("POWER HEAD 1"), font=(ftlab), bg="orange", fg="black")
labelpwrhd1.place(x=0, y=450)
labelpwrhd1gpio= tk.Label(root, text=("GPIO 11"), font=(ftlab), bg="black", fg="white")
labelpwrhd1gpio.place(x= 670, y=450)
labelpwrhd1state= tk.Label(root, font=(ftlab), fg="black")
labelpwrhd1state.place(x=550, y=446)
labelpwrhd1state.configure(text=' On ' if GPIO.input(11) else ' Off ')
#setup powerhead 2 buttons and labels
labelpwrhd2= tk.Label(root, text=("POWER HEAD 2"), font=(ftlab), bg="orange", fg="black")
labelpwrhd2.place(x=0, y=496)
labelpwrhd2gpio= tk.Label(root, text=("GPIO 9"), font=(ftlab), bg="black", fg="white")
labelpwrhd2gpio.place(x= 670, y=496)
labelpwrhd2state= tk.Label(root, font=(ftlab), fg="black")
labelpwrhd2state.place(x=550, y=496)
labelpwrhd2state.configure(text=' On ' if GPIO.input(9) else ' Off ')
root.mainloop()