简体   繁体   中英

Tkinter Checkbutton not updating for LED light control with PyMata

Trying to get my GUI to communicate with PyMata to turn an LED off and on based on the check button The wiring and PyMata code is fine since I can get the LED to blink off and on again but I cant get the LED to turn off or on based on the checkbox My checkbox has this as the code right now

light_state = BooleanVar()
light = Checkbutton(window, text='LED Light', font = ("Times New Roman",10), var = light_state, onvalue=True, offvalue=False)

and my pymata loop is

while True:
    window.update()
    if light_state==True:
        board.digital[pinLED].write(1)
    elif light_state==False:
        board.digital[pinLED].write(0)

Any help is appreciated

After setting print statements to see what was happening to the variable it kept printing PY_VAR0 which I found was cause the variable wouldn't update its self you had to get it using the.get command. My code turned into

while True:
    window.update()
    if light_state.get()==True:
        board.digital[pinLED].write(0)
    elif:
        board.digital[pinLED].write(1)

and all works well now, hopefully this helps someone else sometime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM