当滑块更新时,Tkinter Python窗口崩溃

时间:2016-06-12 20:03:40

标签: python user-interface tkinter

大家好,只是想知道是否有人可以给我一些帮助。试图制作一个python脚本来控制一个覆盆子pi的温室,目前仍处于早期阶段。

问题是我需要循环某段代码才能循环,所以它会不断保持正确的温度等等。我希望只要变量等于1就会发生这种情况,这是由GUI按钮控制的(并且工作正常)。就像测试一样,我得到了从滑块打印温度(值)的代码,但是当它改变时,Tkinter窗口崩溃(Not Responding)。任何人都知道原因或有解决方法。

整个代码:#

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()

0 个答案:

没有答案