import serial import time import tkinter def quit(): global tkTop ser.write(bytes('L', 'UTF-8')) tkTop.destroy() def set_button1_state(): varLabel.set("Index finger UP") ser.write(bytes('H', 'UTF-8')) def set_button2_state(): varLabel.set("Index finger DOWN") ser.write(bytes('L', 'UTF-8')) def set_button3_state(): varLabel.set("Middle finger UP") ser.write(bytes('A', 'UTF-8')) def set_button4_state(): varLabel.set("Middle finger DOWN") ser.write(bytes('B', 'UTF-8')) def set_button5_state(): varLabel.set("Ring finger UP") ser.write(bytes('C', 'UTF-8')) def set_button6_state(): varLabel.set("Ring finger DOWN") ser.write(bytes('D', 'UTF-8')) def set_button7_state(): varLabel.set("Pinky UP") ser.write(bytes('E', 'UTF-8')) def set_button8_state(): varLabel.set("Pinky DOWN") ser.write(bytes('F', 'UTF-8')) def set_button9_state(): varLabel.set("Thumb UP") ser.write(bytes('P', 'UTF-8')) def set_button10_state(): varLabel.set("Thumb DOWN") ser.write(bytes('Q', 'UTF-8')) ser = serial.Serial('/dev/cu.usbmodem14301', 9600) print("Reset Arduino") time.sleep(3) ser.write(bytes('L', 'UTF-8')) tkTop = tkinter.Tk() tkTop.geometry('300x200') tkTop.title("IoT24hours") label3 = tkinter.Label(text = 'Python GUI to interface a XIAO RP2040 for a Prosthetic manipulator project,' '\n and control Servos',font=("Courier", 12,'bold')).pack() varLabel = tkinter.IntVar() button1 = tkinter.IntVar() button1state = tkinter.Button( text="Index finger UP", command=set_button1_state, height = 2, fg = "black", width = 10, bd = 5, activebackground='green' ) button1state.pack(side='top', ipadx=10, padx=10, pady=15) button2 = tkinter.IntVar() button2state = tkinter.Button( text="Index finger DOWN", command=set_button2_state, height = 2, fg = "black", width = 10, bd = 5 ) button2state.pack(side='top', ipadx=10, padx=10, pady=15) button3 = tkinter.IntVar() button3state = tkinter.Button( text="Middle finger UP", command=set_button3_state, height = 2, fg = "black", width = 10, bd = 5 ) button3state.pack(side='top', ipadx=10, padx=10, pady=15) button4 = tkinter.IntVar() button4state = tkinter.Button( text="Middle finger DOWN", command=set_button4_state, height = 2, fg = "black", width = 10, bd = 5 ) button4state.pack(side='top', ipadx=10, padx=10, pady=15) button5 = tkinter.IntVar() button5state = tkinter.Button( text="Ring finger UP", command=set_button5_state, height = 2, fg = "black", width = 10, bd = 5 ) button5state.pack(side='top', ipadx=10, padx=10, pady=15) button6 = tkinter.IntVar() button6state = tkinter.Button( text="Ring finger DOWN", command=set_button6_state, height = 2, fg = "black", width = 10, bd = 5 ) button6state.pack(side='top', ipadx=10, padx=10, pady=15) button7 = tkinter.IntVar() button7state = tkinter.Button( text="Pinky UP", command=set_button7_state, height = 2, fg = "black", width = 10, bd = 5 ) button7state.pack(side='top', ipadx=10, padx=10, pady=15) button8 = tkinter.IntVar() button8state = tkinter.Button( text="Pinky DOWN", command=set_button8_state, height = 2, fg = "black", width = 10, bd = 5 ) button8state.pack(side='top', ipadx=10, padx=10, pady=15) button9 = tkinter.IntVar() button9state = tkinter.Button( text="Thumb UP", command=set_button9_state, height = 2, fg = "black", width = 10, bd = 5 ) button9state.pack(side='top', ipadx=10, padx=10, pady=15) button10 = tkinter.IntVar() button10state = tkinter.Button( text="Thumb DOWN", command=set_button10_state, height = 2, fg = "black", width = 10, bd = 5 ) button10state.pack(side='top', ipadx=10, padx=10, pady=15) tkButtonQuit = tkinter.Button( tkTop, text="Quit", command=quit, height = 4, fg = "black", width = 10, bg = 'yellow', bd = 5 ) tkButtonQuit.pack(side='top', ipadx=10, padx=10, pady=15) tkinter.mainloop()