I'm trying to combine aruino RFID reading capabilities with python tkinter to make a desktop appication. Here, I used a function to create a toplevel which start listening to the serial port. It works perfectly fine when reading values, but if I try to move it, use 'Stop Scan' button it freezes and closes without any errors in terminal.
Toplevel function:
def scanWindow():
scan_window = Toplevel(root)
scan_window.attributes('-topmost', 'true')
scan_window.geometry('300x300')
scan_window.title('RFID Scanner')
Label(scan_window, text="Enter user RFID tag to the scanner...", fg = "dark green", font = "Helvetica 10").place(x=150, y=150, anchor="center")
scan_close = ttk.Button(scan_window, text="Stop Scan", command=lambda: scan_window.destroy()).place(x=150, y=270, anchor="center")
scan_window.after(100, scan_port, scan_window)
scan_port
function:
ser = serial.Serial('COM3', 9600)
ser.flushInput()
def scan_port(cur_window):
ser_bytes = ser.readline()
str_rn = ser_bytes.decode()
str = str_rn.rstrip().strip()
re_val = re.findall("[A-Z0-9][A-Z0-9] [A-Z0-9][A-Z0-9] [A-Z0-9][A-Z0-9] [A-Z0-9][A-Z0-9]", str)
if(len(re_val) == 1):
check_id_details(str)
cur_window.destroy()
How can I avoid the freezing?
I feel like the error is in scan_port
function but can't put my finger on it.
Any help is really appreciated.