# -*- coding: GBK -*-
from tkinter import *
import subprocess
def btn_click():
evalue = Ping() #单击按钮调用PING函数
#text.insert(INSERT,evalue.s)
def btn_phct():
phct()
def phct():
ip = ('172.23.128.%d' %(x) for x in range(1,56))
for i in ip:
str_ip = str('ping -n 1 -w 1 %s ' %i)
ret = subprocess.call(str_ip,stdout=subprocess.PIPE,shell=True)
if ret ==0:
text.insert(INSERT,"%s is OK!\n" % i)
text.update()
#print("OK")
elif ret == 1:
text.insert(INSERT,"%s is faild!\n" % i)
def Ping():
v=('172.23.130.%d' % (x) for x in range(1,11))
for it in v:
loop = str('ping -n 1 -w 1 %s' % it)
ret = subprocess.call(loop,stdout=subprocess.PIPE,shell=True)
if ret ==0:
text.insert(INSERT,("%s is OK!\n" % it))
text.update()
#print("OK")
elif ret == 1:
text.insert(INSERT,("%s is faild!\n" % it))
#print("faild")
'''
if ret:
s = str('ping %s fail \n' % it )
text.insert(INSERT,s)
else:
s=str('ping %s OK \n' % it )
text.insert(INSERT,s)'''
root = Tk()
root.title('Ping')
main_frame = Frame(root)
text_frame=Frame(main_frame)
botton_frame=Frame(main_frame)
l1 = Label(main_frame,text='机台连线')
l1.pack(side='top')
b = Button(botton_frame,text='SORTER',command=btn_click)
b1 = Button(botton_frame,text='HCT',command=btn_phct)
b['width']=10
b['height']=2
b1['width']=10
b1['height']=2
b.pack(side = TOP)
b1.pack(side = TOP)
text = Text(text_frame,width = 30, height= 25)
text.pack(side=TOP)
main_frame.pack()
botton_frame.pack(side='right')
text_frame.pack(side='left')
root.mainloop()