forked from furas/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-1.py
More file actions
35 lines (23 loc) · 701 Bytes
/
Copy pathexample-1.py
File metadata and controls
35 lines (23 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import tkinter as tk
import subprocess
'''Command takes some time so it freezes GUI'''
# --- functions ---
def ping():
# without `shell=True` - cmd as list
cmd = ["ping", "-c", "2", entry.get()]
output = subprocess.check_output(cmd)
# with `shell=True` - cmd as string
#cmd = "ping -c 2 {}".format(entry.get())
#output = subprocess.check_output(cmd, shell=True)
result.insert('end', output.decode('utf-8'))
# --- main ---
root = tk.Tk()
l = tk.Label(root, text="Enter IP or host")
l.pack()
entry = tk.Entry(root, textvariable=entry)
entry.pack()
b = tk.Button(root, text="RUN", command=ping)
b.pack()
result = tk.Text(root)
result.pack()
root.mainloop()