Tkinter Checkbutton not updating for LED light control with PyMata

178 Views Asked by At

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

1

There are 1 best solutions below

0
On

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