I am having problems with my TKinter application when run for long periods of time. The application is simple it receives serial data through usb and prints it on the TK window. It works fine for a long time but when left for hald a day or overnight it is not responsive and I get the generic windows (not responding) error on the application bar at the top, if I try to minimise or close the window it may take up to 5~10 minutes to do it.
I do not get any errors on the python terminal window
I have changed my battery and power setting on my computer to not sleep and normal performance, still not resolved problem
I have stripped my code to the bare minimum to see if it was a section of code cousing the trouble
Here is my code posted below, hopefully some one can shed some light on this for me.
import tkinter as tk
from tkinter import *
from tkinter import ttk
import serial
import numpy
import sys
arduinoData = serial.Serial('com7', 115200) #Creating our serial object named arduinoData
# Main Tkinter application
class Application(Frame):
# Init the variables & start measurements
def __init__(self, master=None):
Frame.__init__(self, master)
root.title( "Dashboard")
root.state('zoomed')
self.grid(row=0, column=0, sticky="nsew")
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=3)
self.B1 = StringVar()
self.createWidgets()
self.pack()
self.measure()
# Create display elements
def createWidgets(self):
self.temperature = Label(self, text="", font=('Verdana', 20)).grid(row=5, column=0,padx=100,pady=200)
# Read the incoming serial data and display it
def measure(self):
if(arduinoData.inWaiting()>0): #Wait till there is data to read
arduinoString = arduinoData.readline() #read serial data
arduinoString =str(arduinoString,'utf-8') #Removes the surrounding rubbish
self.B1.set(str(arduinoString)) #Set the label to the received arduino data
self.B1DO = Label(self, textvariable=self.B1, font=('Verdana', 15)).grid(row=0, column=0, sticky="nsew")
arduinoData.flushOutput() #Clear old data
arduinoData.flushInput()
self.after(1000,self.measure) #Wait 1 second between each measurement
# Create and run the GUI
root = Tk()
app = Application(master=root)
app.mainloop()