Python Tkinter, Update every second Python Tkinter, Update every second tkinter tkinter

Python Tkinter, Update every second


Yes, you will need to create a method to update the values, and add that method to the tkinter mainloop with after. I'd recommend naming it something else, because update is already a tkinter method.

As a totally untested guess:

class Screen(tk.Frame):    def __init__(self, ADC, parent, controller):        tk.Frame.__init__(self, parent)        self.ADC = ADC        lbl = ttk.Label(self, text = "Test Display", background = "grey")        lbl.grid(column = 7, row = 8)        self.lblTestDisplay = ttk.Label(self, foreground = "lime", background = "black")        self.lblTestDisplay.grid(column = 7, row = 9, sticky = "ew")        self.adc_update() # start the adc loop    def adc_update(self):        displayText = self.ADC.ReadValues() #this method returns a list of values        for i in range(len(displayText)):            displayText[i] = round(displayText[i], 2)        self.lblTestDisplay.config(text = str(displayText)) # update the display        self.after(1000, self.adc_update) # ask the mainloop to call this method again in 1,000 milliseconds

Note I also split your label creation into 2 lines, one to initialize and one to layout. The way you had it is very bad; it leads to the variable assigned to None which leads to bugs.