[Python] How to bind Raspberry's GPIO events to invoke TTK buttons?

Discussão em 'Python' iniciado por Stack, Janeiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    Here is the code that works with keyboard events. I'd like to do the same with gpio State changes instead of key_press events. Thks :

    from tkinter import *
    from tkinter import ttk
    import keyboard

    root = Tk()

    def p():
    print('hello')

    BUT_Quitter = ttk.Button ( root , text = "Quitter" , command = root.destroy )
    BUT_Quitter.pack ( )
    BUT_display = ttk.Button ( root , text = "Hello" , command = p )
    BUT_display.pack ( )

    def key_press(event):
    key = event.char
    if key=='q':
    BUT_display.invoke()

    root.bind('<Key>', key_press)

    root.mainloop ( )


    PS : without threading

    Continue reading...

Compartilhe esta Página