TA的每日心情 | 慵懒 2016-12-14 12:39 |
---|
签到天数: 41 天 [LV.5]常住居民I
|
python 可以作为一个胶水语言让我们在处理shell及运维时比较方便,但是对于gui这块就比较弱了,常见的就像tkinter,pyqt,wx。因为我是使用python3做开发环境所以我选择了tkinter
tkinter 作为python的gui比较简单但是好在是python3也可以使用,入门并不难。
主文件:
[AppleScript] 纯文本查看 复制代码 #Build : 2015/11/22
#Author: Corno
#Version: Python 3.4
from tkinter import *
import sys,os
from urllib import request,parse
import re
from socket import setdefaulttimeout
setdefaulttimeout(30)
#定义测试函数
def Test():
print('ok')
#定义ping窗口,调用外部ping模块
def NetWork_Ping():
#调用外部Windows_Ping模块
import Windows_Ping
Windows_Ping.run_ping(root)
def spride_get():
Header ={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36'}
KeyWords = Search_KeyWords.get("1.0",END)
url_encode = parse.urlencode({'wd': KeyWords})
Header_URL = request.Request('http://www.baidu.com/s?wd=%s$pn=10'%url_encode,headers=Header)
code = request.urlopen(Header_URL).read().decode('utf8')
#print(url_encode)
#code = request.urlopen('http://www.baidu.com/?%s'%url_encode).read().decode('utf8')
#Re_Rule = r'<div class="f13"><span class="g">(.*?) </span><div class="c-tools" id=".*?" .*?">'
#Com_Rule = re.compile(Re_Rule)
#Find_Content = re.findall(Com_Rule,code)
print(code)
#定义程序主体框架
root = Tk()
root.title('Corno Tools')
root.minsize(600,650)
root.maxsize(600,650)
#定义总菜单栏
MenuTools = Menu(root)
#定义网络工具栏
NetWorkTools = Menu(MenuTools,tearoff=1)
NetWorkTools.add_command(label='Ping',command=NetWork_Ping)
NetWorkTools.add_command(label='Tracert',command=Test)
NetWorkTools.add_command(label='WhoAmI',command=Test)
NetWorkTools.add_separator()
NetWorkTools.add_command(label='Exit',command=root.quit)
MenuTools.add_cascade(label='NetWorkTools',menu=NetWorkTools)
#定义帮助菜单栏
About = Menu(MenuTools,tearoff=1)
About.add_command(label='Author',command=Test)
MenuTools.add_cascade(label='About',menu=About)
#定义百度爬虫框架
Spride_Frame = LabelFrame(root,text='百度爬虫',height=200,width=650)
Spride_Frame.grid(row=0,column=0)
Search_lab = Label(Spride_Frame,text='关键字:')
Search_lab.grid(row=0,column=0,)
Search_KeyWords = Text(Spride_Frame,height=1,width=60)
Search_KeyWords.grid(row=0,column=1)
Search_Page = Text(Spride_Frame,height=1,width=3)
Search_Page.grid(row=0,column=2)
Search_Submit = Button(Spride_Frame,text='查找链接',command=spride_get)
Search_Submit.grid(row=0,column=2)
Search_Result_SrcollBar = Scrollbar(Spride_Frame)
Search_Result_SrcollBar.grid(row=1,column=2,sticky=W)
Search_Result = Text(Spride_Frame,height=10,width=60,yscrollcommand=Search_Result_SrcollBar.set)
Search_Result_SrcollBar.config(command = Search_Result.yview)
Search_Result.grid(row=1,column=0,columnspan=4)
#程序菜单栏及主体框架
root.config(menu=MenuTools)
root.mainloop()
Windows_Ping模块:
[AppleScript] 纯文本查看 复制代码 from tkinter import *
import os
import re
def run_ping(root):
NetWork_Ping = Toplevel(root)
NetWork_Ping.title('NetWorkTools_Ping')
NetWork_Ping.maxsize(450,200)
NetWork_Ping.minsize(450,200)
#ping option
Ping_Label_ADD = Label(NetWork_Ping,text='IP ADD:')
Ping_Label_ADD.grid(row=0,column=0)
Ping_Input = Entry(NetWork_Ping,width=20)
Ping_Input.grid(row=0,column=1)
Ping_Label_Length = Label(NetWork_Ping,text='数据包大小:')
Ping_Label_Length.grid(row=0,column=2)
Ping_Length_text = Entry(NetWork_Ping,width=3)
Ping_Length_text.grid(row=0,column=3)
Ping_Label_Packs = Label(NetWork_Ping,text='数据包个数:')
Ping_Label_Packs.grid(row=0,column=4)
Ping_Packs_text = Entry(NetWork_Ping,width=3)
Ping_Packs_text.grid(row=0,column=5)
Ping_Prompt = Label(NetWork_Ping,text='请填写正确IP地址或域名,数据包大小及数据包个数均为数字!',fg='red')
Ping_Prompt.grid(row=2,column=0,columnspan=10)
#input error prompt
def check_result():
Ping_Add = Ping_Input.get()
Ping_len = Ping_Length_text.get()
Ping_packs = Ping_Packs_text.get()
Check_Result_Frame = Frame(NetWork_Ping)
Check_Result_Frame.grid(row=3,column=0,columnspan=10)
try:
if Ping_len =='' and Ping_packs !='':
Get_packs = int(Ping_packs)
Input_Prompt = Label(Check_Result_Frame,text='输入正确,等待结果!',fg='blue')
Input_Prompt.grid(row=0,column=0,columnspan=10)
#print('ping %s -n %s'%(Ping_Add,Get_packs))
Ping_text = os.popen('ping %s -n %s'%(Ping_Add,Get_packs))
Ping_end = Ping_text.read()
Ping_Result.insert('0.0',Ping_end)
if Ping_len !='' and Ping_packs =='':
Get_len = int(Ping_len)
Input_Prompt = Label(Check_Result_Frame,text='输入正确,等待结果!',fg='blue')
Input_Prompt.grid(row=0,column=0,columnspan=10)
#print('ping %s -l %s'%(Ping_Add,Get_len))
Ping_text = os.popen('ping %s -l %s'%(Ping_Add,Get_len))
Ping_end = Ping_text.read()
Ping_Result.insert('0.0',Ping_end)
if Ping_len !='' and Ping_packs !='':
Get_len = int(Ping_len)
Get_packs = int(Ping_packs)
Input_Prompt = Label(Check_Result_Frame,text='输入正确,等待结果!',fg='blue')
Input_Prompt.grid(row=0,column=0,columnspan=10)
#print('ping %s -l %s -n %s'%(Ping_Add,Get_len,Get_packs))
Ping_text = os.popen('ping %s -l %s -n %s'%(Ping_Add,Get_len,Get_packs))
Ping_end = Ping_text.read()
Ping_Result.insert('0.0',Ping_end)
if Ping_len =='' and Ping_packs =='':
Input_Prompt = Label(Check_Result_Frame,text='输入正确,等待结果!',fg='blue')
Input_Prompt.grid(row=0,column=0,columnspan=10)
#print('ping %s '%Ping_Add)
Ping_text = os.popen('ping %s'%Ping_Add)
Ping_end = Ping_text.read()
Ping_Result.insert('0.0',Ping_end)
except ValueError:
Input_Prompt = Label(Check_Result_Frame,text='输入错误,重新输入!',fg='red')
Input_Prompt.grid(row=0,column=0,columnspan=10)
#print('valueerror')
Ping_Submit = Button(NetWork_Ping,text='开始',command=check_result)
Ping_Submit.grid(row=0,column=6)
#ping result
Result_Frame = Frame(NetWork_Ping)
Ping_Scroll = Scrollbar(Result_Frame)
Ping_Result = Text(Result_Frame,height=10,width=60,yscrollcommand=Ping_Scroll.set)
Ping_Result.pack(side=LEFT,fill=Y)
Ping_Scroll.pack(side=LEFT,fill=BOTH)
Result_Frame.grid(row=4,column=0,columnspan=10)
Ping_Scroll.config(command = Ping_Result.yview)
NetWork_Ping.mainloop()
功能就只有一个ping,现在我还在想要做什么功能,大家也可以根据这个框架自己写功能模块。
源文件代码.rar
(2.28 KB, 下载次数: 9)
|
|