- 生肖
- 虎
- 星座
- 狮子座
- 自我介绍
- 新年第一天据说有雨,全民齐赏日出的计划恐要泡汤。”宋仁宗拍着包拯的肩,“朕决定把你悬挂在城门上。”“但微臣额上的不是太阳是月亮啊!”“没事,挂久一点就会升级成太阳
- 性别
- 男
- 积分
- 368
- 积分
- 739
- 精华
- 0
- 阅读权限
- 150
- 注册时间
- 2012-4-28
- 最后登录
- 2016-9-20
- 帖子
- 247
- 自我介绍
- 新年第一天据说有雨,全民齐赏日出的计划恐要泡汤。”宋仁宗拍着包拯的肩,“朕决定把你悬挂在城门上。”“但微臣额上的不是太阳是月亮啊!”“没事,挂久一点就会升级成太阳
- 生肖
- 虎
- 星座
- 狮子座
- 性别
- 男
|
doping.py
- import os
- import commands
- import time
- import mytimer
- from Tkinter import *
- class Application(Frame):
- def doPing(self):
- cmd = "ping "
- cmd = cmd + self.v.get()
- pintime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
- print cmd, " please waite",pintime
- usr = os.popen(cmd,'r').read()
- usr= str(usr)
- usr = usr.replace('\r\n','\n')
- usr = pintime +"\n"+usr + self.v.get() + "\n-------------------------------\n"
- print usr
- self.area.insert(1.0,usr)
- def multiping(self):
- thread1 = mytimer.mytimer(1,1,'www.baidu.com',self.area)
- thread2= mytimer.mytimer(2,2,'192.168.0.1',self.area)
- thread3 = mytimer.mytimer(3,3,'localhost',self.area)
- thread1.start()
- thread2.start()
- thread3.start()
- def clr(self):
- self.area.delete(1.0,END)
- def createWidgets(self):
- self.area=Text(self,height=30,width=50)
- self.area.grid(row=2,column=0,columnspan=5)
- self.btn_quit = Button(self, text="Quit", fg="red", command=self.quit)
- self.btn_quit.grid(row=0,column=0)
- self.btn_clr = Button(self,text="清除",command=self.clr )
- self.btn_clr.grid(row=0,column=2)
- self.btn_ping = Button(self, text="ping", command=self.doPing)
- self.btn_ping.grid(row=0,column=1,columnspan=2)
- self.btn_ping = Button(self, text="multiping", command=self.multiping)
- self.btn_ping.grid(row=0,column=3,columnspan=2)
- MODES = [
- ("localhost", "localhost"),
- ("route", "192.168.0.1"),
- ("baidu", "www.baidu.com"),
- ("qq", "www.qq.com"),
- ]
- self.v = StringVar()
- self.v.set("localhost") # initialize
- i = 0
- for text, mode in MODES:
- self.b = Radiobutton(self, text=text,
- variable=self.v, value=mode)
- self.b.grid(row=1,column=i)
- i = i+1
- def __init__(self,master=None):
- Frame.__init__(self, master)
- self.pack()
- self.createWidgets()
- root = Tk()
- root.geometry("410x550+0+0")
- app = Application(master=root)
- app.mainloop()
- root.destroy()
复制代码 mytimer.py
- import threading
- import time
- import os
- class mytimer(threading.Thread):
- def __init__(self, num, interval,web,area):
- threading.Thread.__init__(self)
- self.thread_num = num
- self.interval = interval
- self.thread_stop = False
- self.web = web
- self.rs = ""
- self.area = area
- def run(self):
- #while not self.thread_stop:
- #print 'Thread Object(%d),Time:%s\n' % (self.thread_num,time.ctime())
- #time.sleep(self.interval)
- cmd="ping "+self.web
- #os.system(cmd)
- rs = os.popen(cmd).read()
- self.rs =rs
- #print rs
- def __del__(self):
- print self.rs
- self.area.insert(1.0,self.rs)
- def stop(self):
- self.thread_stop = True
- def test():
- thread1 = mytimer(1,1,'www.baidu.com')
- thread2= mytimer(2,2,'192.168.0.1')
- thread3 = mytimer(3,3,'localhost')
- thread1.start()
- thread2.start()
- thread3.start()
- ##time.sleep(10)
- thread1.stop()
- thread2.stop()
- thread3.stop()
- return
- if __name__ == '__main__':
- test()
复制代码 |
|