Need help solving this problem, I'm a beginner going crazy over this. Each time I press "pingButton1" I want the "pingResult1" to refresh the information insteed of adding new every time I press it. It's a simple "check if ping is good" program.
Any suggestions?
I've tried using google but nothing is working for me.
from tkinter import * import os import subprocess from time import sleep menu = Tk() menu.title("Panel") menu.geometry("250x380+700+500") menu.resizable(0, 0) menu.configure(background="#0d335d") def close(): screen.destroy() def pingWindow1(): global ip1 global pingButton1 global screen screen = Toplevel(menu) screen.title("Ping Windows") screen.geometry("300x250+650+300") screen.configure(background="#0d335d") blank = Label(screen, bg="#0d335d", text="") blank.pack() ip1 = Entry(screen, width=20, bg="white") ip1.pack() blank1 = Label(screen, bg="#0d335d", text="") blank1.pack() pingButton1 = Button(screen, text="Ping away..", width="20", bg="#e5e5e5", height="2", borderwidth=2, relief="ridge", command=pingResult1) pingButton1.pack() close_ping = Button(screen, text="Close", width="20", bg="#e5e5e5", height="2", borderwidth=2, relief="ridge", command=close) close_ping.pack() blank2 = Label(screen, text="", bg="#0d335d") blank2.pack() screen.bind('<Escape>', lambda _: close()) def pingResult1(): global pingIP1 pingIP1 = ip1.get() try: overall_mgm() except: return False try: overall_mgm_RO() except: return False done = Label(screen, text="Completed").pack() def overall_mgm(): response = os.system("ping -c 1 sekiiws00"+pingIP1) if response is not 0: fail = Label(screen, bg="black", fg="red", text="KI FAILED").pack() else: success = Label(screen, bg="black", fg="green", text="KI SUCCESS").pack() def overall_mgm_RO(): response = os.system("ping -c 1 seroiws00"+pingIP1) if response is not 0: fail = Label(screen, bg="black", fg="red", text="RO FAILED").pack() else: success = Label(screen, bg="black", fg="green", text="RO SUCCESS").pack() # Widget option = Button(menu, text="Ping IP", width="20", bg="#e5e5e5",height="2", borderwidth=2, relief="ridge", command=pingWindow1) # Out option.pack() menu.mainloop() I'm guessing I need something like this
if pingButton1 clicked more than once refresh current Labels( fail & success) def pingResult1(): global pingIP1 pingIP1 = ip1.get() try: overall_mgm() except: return False try: overall_mgm_RO() except: return False done = Label(screen, text="Completed").pack() https://stackoverflow.com/questions/66439427/tkinter-button-replacing-old-info-with-new-when-pressed March 02, 2021 at 08:30PM
没有评论:
发表评论