I'm trying to create a tool that help me to my work, so I want to change the button color to green if ping is successful and unsuccessful if not.
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
import os
window = Tk()
window.geometry("500x500")
window.title("ping Tool")
def ping(*branch):
for ip in branch:
response = os.popen(f"ping {ip}").read()
if "Received = 4" in response:
print(f"up {ip} Ping Successful")
else:
print(f"Down {ip} Ping Unsuccessful")
def ping201():
ping('4.2.2.2')
def ping202():
ping('8.8.8.8')
button = ttk.Button(window, text='branch1', command=ping201)
button.grid(row=0, column=0)
button = ttk.Button(window,text='branch2',command=ping202)
button.grid(row=1, column=0)
button = ttk.Button(window,text='Exit',command=window.quit)
button.grid(pady=20)
window.mainloop()