I created a script that dynamically add/remove/updates a label in a window. The only problem I am having is that the old frames labels doesn't disappear.. The problem leads to some label disturbing in the bg of the windows and of course this leads to some kind of memory leak ( not sure if its the proper term here..).
This is my code:
import tkinter as tk
from tkinter.ttk import *
from subprocess import call,Popen,PIPE, STDOUT
class App():
def __init__(self):
self.root = tk.Tk()
self.root.title("devices networks")
self.update_clock()
self.root.mainloop()
def update_clock(self):
i=0
adb_absolute_path = "C:\\Users\\ilan.MAXTECH\\AppData\\Local\\Android\\Sdk\\Platform-tools\\"
# Get the list of connected devices
cmd = adb_absolute_path+"adb.exe devices"
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
device_list = proc.communicate()[0].decode().split("\r\n")
# remove unnecessary text in devices call
device_list.pop(0)
device_list.remove("")
device_list.remove("")
#### not working.... #######
# #erase the old labels ( in case a device has been disconected
# for line in range(10):
# lb = Label(self.root, text="")
# lb.grid(row=1, column=line)
###########################
#print netcfg for each device
for device in device_list:
#get the netcfg for specific device
device_serial = device.split("\t")[0]
cmd = adb_absolute_path + "adb.exe -s " + device_serial + " shell netcfg"
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
netcfg_output = proc.communicate()[0].decode()
#add a new label to the screen
lb = Label(self.root, text=device_serial+"\n"+netcfg_output)
lb.grid(row=1, column=i)
lbblank = Label(self.root,text="\t\t")
lbblank.grid(row=1, column=i+1)
i += 2
self.root.geometry(str(device_list.__len__()*450)+"x700")
self.root.after(1000, self.update_clock)
app=App()
Here are some screen shots :
3 devices are connected then 3 labels are shown:
2 devices are connected then 2 labels are shown:
New labels are on top an old ones: