import tkinter import serial import threading import time s=serial.Serial("COM6"); top = tkinter.Tk() def polema(): s.write(b'a'); def kustu(): s.write(b'b') def kysiAsend(): s.write(b'c') if(s.inWaiting()>0): T1["text"]=s.readline().decode("ascii").strip() def korda(): while True: kysiAsend() time.sleep(1) B = tkinter.Button(top, text ="Põlema", command = polema) B2 = tkinter.Button(top, text ="Kustu", command = kustu) B3 = tkinter.Button(top, text ="Küsi asend", command = kysiAsend) T1=tkinter.Label(top, text="teade") t = threading.Thread(target=korda) t.daemon = True t.start() B.pack() B2.pack() B3.pack() T1.pack() top.mainloop()