I would like to ping every second in my network a certain hostname and change in return the name of the corresponding button. For now I have this :
import tkinter as tk
import time
# variables
hostname = ("ASUS-PC")
mot= "inactif"
class test(tk.Tk):
    # make buttons on grid
    def __init__(self):
        tk.Tk.__init__(self)
        self.button = list()
        for i in range(10):
            i=i+1
            RN = ('RN '+str(i))
            self.button.append(tk.Button(text=RN))
            self.button[-1].grid(row=0,column=i)
    # ping hostname every second
    def ping(self):
        import subprocess
        import os
        result=subprocess.Popen(["ping", "-n", "1", "-w", "200", hostname],shell=True).wait()
        if result == 0:
            print (hostname, "active")
        else:
            B = self.button[0] 
            B ['text'] = mot
        time.sleep(1)
    while True:
        ping()
app = test ()
app.mainloop() 
It doesn't work and I don't know why. At beginning it was a "self" problem but now it seems to be related to how I ping every second (I took it from there What is the best way to repeatedly execute a function every x seconds in Python?) If someone know the answer...
Thanks for your help
 
     
    