Python tkinter file MD5 validation Tool

Source: Internet
Author: User
Tags sha1

"File MD5 validation Tool" written using Python 2.7.10 tkinter. Due to their own level of problems, there may be some mistakes, I beg you to correct, thank you.

Graphical interface:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/77/70/wKiom1Zn13bQQrW6AAAy18QQ_lk918.png "title=" 002. PNG "alt=" Wkiom1zn13bqqrw6aaay18qq_lk918.png "/>

Source:

#coding: utf-8#python tkinter  file MD5 Check # environment  Python 2.7.10 import Tkinter  AS TKIMPORT HASHLIBIMPORT  OSIMPORT TKFILEDIALOG AS TKFDEF VIEW_MD5 ():    #计算结果显示方法     v=[]  #申明输出数组     try:         fmd5=md5_sum (FN)   #调用文件校验方法, and returns the output result          v.extend (['---------------------------------------------\ n '])          v.extend ([' file:{}\n '. Format (FN)])         v.extend ([' Md5  :{}\n '. Format (fmd5[0])         v.extend ([' sha1:{}\n '. Format ( FMD5[1])         v.extend (['----------------------------------------- ----\ n '])     except Exception:         V.extend (['---------------------------------------------\ n '])         v.extend ([' File selection Error! \ n '])         v.extend ([' File does not exist! \ n '])         v.extend ([' Please re-select! \ n '])         v.extend (['---------------------------------------------\ N '])      #将结果逐行插入文本框内     t1.insert (tk. Insert,v[0])     t1.insert (TK. INSERT,V[1])     t1.insert (TK. INSERT,V[2])     t1.insert (TK. INSERT,V[3])     t1.insert (TK. INSERT,V[4])  def get_file ():  #获取文件名和文件绝对路径方法     global fn # Defining global variables for file paths and filenames     D_PWD=OS.GETCWD ()   #获取当前目录位置     fn =  tkf.askopenfilename (initialdir = d_pwd) #设置目录打开初始位置     e1.delete (tk. END)           &NBsp;                # Empty storage file location input box     e1.insert (0,FN)                                 #将填入的文件输入到输入框def  cl_text ():  #清空文本框内容方法     t1.delete (0.0,TK. END) def md5_sum (filename):      #文件校验值计算方法     fd=open ( FileName, "RB")   #打开文件     fd.seek (0)                #将文件打操作标记移到offset的位置     line=fd.readline ()        #读取文件第一行进入line          #md5校验值计算     md5 =HASHLIB.MD5 ()     md5.update (line)      #SHA1校验值计算      SHA1=HASHLIB.SHA1 ()     shA1.update (line)         while line:           #循环读取文件         line=fd.readline ()          md5.update (line)          Sha1.update (line)             fmd5=md5.hexdigest ()    #生成文件MD5校验值     fsha1=sha1.hexdigest () #生成文件SHA1校验值          fsum=[fmd5,fsha1]    fd.close ()        return fsum if __name__ ==  "__main__":     master =  tk. Tk ()     master.title ("File MD5 check")   #标题     #  300X300 represents the size of the main window at initialization, and 200,200 represents the position of the window at the time of initialization     master.geometry (' 520x320+200+200 ')           #创建1个文件标签And is laid out in grid mode.     tk. Label (master, text= "file:", width=10). Grid (row=0,column=0)      #创建1个文件输出输入框, and layout in grid mode.     e1 = tk. Entry (master,width=50,state =  ' normal ')     e1.grid (row=0, column=1)       #创建1个文本输出框 and layout in grid mode.     t1=tk. Text (master,width=50,height=20)     t1.grid (row=1, column=1)           #创建 3 buttons for calculate, select file, empty content, and layout in grid mode.     b1=tk. Button (master,text =  ' compute ', WIDTH=10,COMMAND = VIEW_MD5)     b1.grid (row= 1,column=3,rowspan=1)     b2=tk. Button (master,text =  ' Select File ', Width=10,command = get_file)     b2.grid ( Row=0,column=3,rowspan=1)     b3=tk. Button (master,text =  ' empty content ', Width=10,command = cl_text)     b3.grid (row=1,column=0,rowspan=1)     tk.mainloop () 


This article is from the "Tuk-line" blog, please make sure to keep this source http://lovexm.blog.51cto.com/3567383/1721170

Python tkinter file MD5 validation Tool

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.