import tkinter import serial data= serial.Serial('com31','9600') def on(): data.write(b'H') def off(): data.write(b'L') led=tkinter.Tk() Button=tkinter.Button text=tkinter.Text on=Button(led, text="ON ", command=on, height=10, width=25) off=Button(led, text="OFF", command=off,height=10, width=25) on.pack(side=tkinter.RIGHT) off.pack(side=tkinter.LEFT) led.mainloop()