[quote="scotty101"]You need to share your code so that we can help.
Thanks very much. This is how far I have got. I'm sure there's a lot of tidying up to be done, but I'm sadly stuck. No need to waste your time if you can just point to existing code and think a bit of directed study on the net or anywhere will teach me.
Code: Select all
#! /usr/bin/ python3 /home/pi/pyscripts/PowerOn_Off.py
#this app is simply to control a solid-state relay remotely, using VNCConnect
#it uses GPIO 24 as the controlling signaller
import sys
import datetime
import glob
import subprocess
import time #needed for time.sleep()
import RPi.GPIO as GPIO # import RPi.GPIO module
from tkinter import *
from tkinter import ttk
from sys import exit
strt=datetime.datetime.now()
today=datetime.date.today()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.OUT)
global offwego
offwego='aaaa'
def TurnPowerON():
GPIO.output(24,1)
running()
return
def TurnPowerOFF():
GPIO.output(24,0)
sayoff()
return
def Start():
global root2
root2=Tk()
root2.title('Water pump control')
root2.geometry('350x150+5+50')
w=Label(root2, text='Pump will auto-start at 11 am')
w.config(font=('times',12, 'italic bold'), fg='red', bg='yellow')
w.pack(pady=5)
w=Label(root2, text='Set running time (hours)')
w.config(font=('times',12, 'italic bold'), fg='red', bg='yellow')
w.pack(pady=5)
w1=Spinbox(root2, from_=1, to=4, width=2)
w1.pack(ipadx=3,ipady=7)
w=Button(root2, text='Override: Turn pump ON now)', command=TurnPowerON)
w.config(font=('Arial',12,'bold'),fg='green')
w.pack(pady=5)
global spinsee
spinsee=w1.get()
root2.mainloop()
return
def running():
root2.destroy
rr=Tk()
rr.title('Pump running control')
rr.geometry('550x150+5+50')
w=Label(rr, text='Pump running for ' + spinsee +' hour(s)')
w.config(font=('times',12, 'italic bold'), fg='red', bg='yellow')
w.pack(pady=5)
w=Button(root2, text='Override: Turn OFF & Quit', command=stoppit)
w.config(font=('Arial',12,'bold'),fg='green')
w.pack(side=RIGHT, padx=2,pady=5)
#rr.after(10000,rr.destroy)
rr.mainloop()
return
def stoppit():
global offwego
offwego='bbbb'
return
while offwego=='aaaa': # also tried 'while True:' to get Quit button to work
if offwego=='bbbb':
GPIO.cleanup() #nb need for GPIO.cleanup()
exit(0)
Start()