I am completely new to Python and I am using pyserial to read data from the Arduino and create a GUI using TkInter, which displays the data from the arduino in a text box of the GUI.
I am using this Python code:
from tkinter import *
from tkinter import ttk
import serial
import time
def disp():
ser = serial.Serial('COM1', baudrate = 9600, timeout=1)
time.sleep(1)
arduinoData = (ser.readline().strip())
a=arduinoData.decode('utf-8')
dispe.delete(0,"end")
dispe.insert(0, a)
def dis(event):
disp()
root=Tk()
button=Button(root,text="press")
button.bind("<Button-1>",dis)
button.pack(side=LEFT)
dispe=Entry(root)
dispe.pack(side=LEFT)
root.mainloop()
This code works absolutely fine. When I click the button on the GUI it displays the values received from the Arduino. This program requires the user to click again and again to get the values, but I want to add a while loop so that I don't need to click again and again continuously.The point is to make the user click the button only once.
But when I insert a while True:
loop after time.sleep
to continuously update the values being received from the Arduino, nothing gets displayed on the textbox...