Hi guys just wondering if anyone could give me some assistance. Trying to make a python script to control a greenhouse with a raspberry pi, still in early stages at the moment.
Problem is i need a certain section of code to loop so it continually keeps the correct temp, etc i want this to occur as long as a variable is equal to 1 this is controlled by a GUI button (and works fine). Just as a test i got the code to print the temprature (value) from the slider but when its changed the Tkinter window crashes (Not Responding). Anyone know the reason or have a fix.
Entire Code:#
from tkinter import *
root = Tk()
import time
#--------------------VARIABLES--------------------#
ManOverideToggleINT = 0
AUTOMODETOGGLESTATEINT = 0
#------------------TKINTER SETUP------------------#
root.title("GREENHOUSE CONTROL - GUI")
root.geometry('800x480')
#root.attributes('-fullscreen', True) #MAKE IT FULL SCREEN UN-COMMENT WHEN CODE DONE
#---------------CONTROLS AUTO MODE----------------#
"""
This function will control the greenhouse when
manual overide in not engaged (==1), monitor temp,
humidity, etc.
MORE RESEARCH NEEDED ON PLANTS NEEDS
"""
def AUTO():
global AUTOMODETOGGLESTATEINT
while AUTOMODETOGGLESTATEINT == 0:
print(CONSTEMP.get())
time.sleep(5)
"""
##############
GPIO PINS NEEDED INPUTS/OUTPUTS
##############
COOLING IF TOO WARM
if (realtemp>CONSTEMP.get()):
print("Cooling activated" + realtemp + " > " CONSTEMP.get() + " (desired)")
COOLING OFF IF TOO WARM
elif (realtemp<CONSTEMP.get()):
print("Cooling deactivted" + realtemp + " < " CONSTEMP.get() + " (desired)")
"""
print("AUTO LOOP HERE")
#--------------CONTROLS MANUAL MODE---------------#
"""
Manual mode will allows the user to specify
specific conditions inside the green house
"""
def MANUAL():
global AUTOMODETOGGLESTATEINT
if AUTOMODETOGGLESTATEINT == 1:
print("AUTO REGULATION HAS BEEN TURNED OFF")
print("LOOP UNTILL BACK ON")
#def ToggleWait():
def AUTOMODETOGGLE():
global AUTOMODETOGGLESTATEINT
if AUTOMODETOGGLESTATEINT == 0:
print("Auto Mode OFF")
TOGGLE["text"] = "AUTO REGULATION = OFF"
AUTOMODETOGGLESTATEINT = 1
MANUAL()
else:
print("AUTO REGULATION = ON")
TOGGLE["text"] = "AUTO REGULATION = ON"
AUTOMODETOGGLESTATEINT = 0
AUTO()
TOGGLE = Button(root, text="AUTO REGULATION = ON", command=AUTOMODETOGGLE)
TOGGLE.pack()
CONSTEMP = Scale(root, orient=HORIZONTAL, length=300, width=50,from_=10,to=40,tickinterval=5,)#25c is optinum
CONSTEMP.pack()
root.mainloop()