Ich hab mal bissl probiert, das kam dabei heraus:
Code: Alles auswählen
import tkinter
from tkinter import Frame, Label, NSEW, Entry, Button
import subprocess
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.hauptframe()
def hauptframe(self):
menue_frame = Frame(root, name='haupt_frame', width=500, height=150)
menue_frame.focus_set()
menue_frame.grid(row=1, sticky=NSEW)
Label(menue_frame, text="Geben Sie eine IP oder eine Host-Adresse für den Ping ein:", font=15, width=20).grid(row=1, column=1, pady=5, padx=5, sticky=NSEW)
self.host = Entry(menue_frame, width=20, font=15)
self.host.grid(row=1, column=2, sticky=NSEW)
Button(menue_frame, text="Ping", width=20, command=self.shell, takefocus=1).grid(row=8, column=2, pady=5, padx=5, sticky=NSEW)
def shell(self):
ping = subprocess.Popen(['ping', '-c 2', self.host.get()], stdout=subprocess.PIPE).communicate()[0]
print(ping)
root = tkinter.Tk()
root.title('ping')
app = Application(root)
root.mainloop()
Kann man die Ausgabe eigentlich noch bissl anpassen? Weil bei mir wird in der Ausgabe alles in eine Zeile geschrieben, schöner wäre es wenn er nach jedem Ping eine neue Zeile beginnt.