Tkinter Gui acts very slow


I created a GUI script using Tkinter which monitoring I/Os PLC.

For digital input information i receive a list of every digital input status (binary).

The problem occurs when i try to update the status of the digital input in real time, i created multiple functions that every function generates a list of digital input and update the list every 1 second using ,after() method , it works fine until i add more widgets to the gui which contain an element from the digital input list - this causes the GUI to work very very slow and i can barely move the GUI window...

I think that .after() method causes that problem , coz i use it in almost every function so it executes multiple function and once that every each update the list of digital input.

These are some classes with functions i used in my code using .after() method:

First class:

class dig_out_but():
def __init__(self, canvas,button, index ,img1,img2):
self.canvas = canvas
self.index = index
self.button = button
self.img1 = img1
self.img2 = img2

def Create_butt(self):
coils_read = md.rd_coils(self.index, 1)

if coils_read[0] == False:
self.button.config(command=lambda: md.wr_coils(self.index, True))
if coils_read[0] == True:
self.button.config(command=lambda: md.wr_coils(self.index, False))

self.canvas.after(50, self.Create_butt)

Second class:

class dig_in_rec():
def __init__(self, canvas , index, x1,y1,x2,y2 ,label, img1 , img2):
self.canvas = canvas
self.index = index
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.img1 = img1
self.img2 = img2

def rec_create(self):

in_arr = md.rd_dig_in(0, 30), y=self.y1)
if in_arr[self.index] == True:

elif in_arr[self.index] == False:

self.canvas.after(500, self.rec_create)

Answers 0

Related Articles