I couldnt something problem solving anywhere, so I think its time to post this question myself.
Here is my code:
import serial
from serial import Serial
import PySimpleGUI as sg
ser = serial.Serial('COM3', 115200, timeout=1)
read = False
sg.theme('DarkAmber')
layout = [ [sg.InputText(), sg.Button('Empfindlichkeit einstellen')],
[sg.Button('start'), sg.Button('end')] ]
window = sg.Window('Window Title', layout)
while True:
event, values = window.read()
if read == True:
reading = ser.readline()
print(reading[0:256])
if event == "start":
read = True
if event == sg.WIN_CLOSED or event == 'end':
break
window.close()
The GUI shows up just perfectly fine and there are no errors. But the problem is the following part:
if read == True:
reading = ser.readline()
print(reading[0:256])
This part of the code should run continuously when I pressed the button that says "start" once. But it doesnt. This part of the code just get executed one time, whenever I have pressed start once and then any other button. How can I fix this?
readline()will block until a newline is received. You need to make the operation non-blocking, or move it to a dedicated, non-GUI thread in which blocking is acceptable.