[开源]文件MD5与SHA1查看器的源代码
初学Python,写了个小工具练练手,把源代码发出来大家一起交流:程序代码:
#!/usr/bin/python # -*- coding: UTF-8 -*- import wx import os import hashlib class MainFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, u'文件MD5/SHA1查看器', size=(410, 260)) self.panel = wx.Panel(self, -1) button = wx.Button(self.panel, -1, u"选择文件", pos=(10, 10)) self.Bind(wx.EVT_BUTTON, self.ShowFileDialog, button) button.SetDefault() self.filesize = wx.TextCtrl(self.panel, -1, "", pos = (45,45), size=(340, -1), style=wx.TE_READONLY) self.filesize.Hide() self.filepath = wx.TextCtrl(self.panel, -1, "", pos = (45,80), size=(340, -1), style=wx.TE_READONLY) self.filepath.Hide() self.filemd5 = wx.TextCtrl(self.panel, -1, "", pos = (45,115), size=(340, -1), style=wx.TE_READONLY) self.filemd5.Hide() self.filesha1 = wx.TextCtrl(self.panel, -1, "", pos = (45,150), size=(340, -1), style=wx.TE_READONLY) self.filesha1.Hide() wx.HyperlinkCtrl(self.panel,-1, u"编程中国", url="http://www.bccn.net/", pos=(10,202)) wx.HyperlinkCtrl(self.panel,-1, u"编程论坛", url="http://bbs.bccn.net/", pos=(68,202)) wx.HyperlinkCtrl(self.panel,-1, u"Python论坛", url="http://bbs.bccn.net/forum-246-1.html", pos=(125,202)) self.Centre() def ShowFileDialog(self, event): dialog = wx.FileDialog(None, u"选择文件", style = wx.OPEN) if dialog.ShowModal() == wx.ID_OK: thefile = dialog.GetPath() self.ShowInfo(thefile) dialog.Destroy() def ShowInfo(self, thefile): wx.StaticText(self.panel, -1, u"大小:", (10,49), (35,15)) self.filesize.Show() self.filesize.Value = str(os.path.getsize(thefile)) wx.StaticText(self.panel, -1, u"路径:", (10,84), (35,15)) self.filepath.Show() self.filepath.Value = thefile wx.StaticText(self.panel, -1, u"MD5:", (10,119), (35,15)) self.filemd5.Show() self.filemd5.Value = hashlib.md5(open(thefile,"rb").read()).hexdigest() wx.StaticText(self.panel, -1, u"SHA1:", (4,154), (35,15)) self.filesha1.Show() self.filesha1.Value = hashlib.sha1(open(thefile,"rb").read()).hexdigest() if __name__ == '__main__': app = wx.PySimpleApp() frame = MainFrame() frame.Show() app.MainLoop()
如果电脑上装了
Python2.6.4(下载地址:https://down.bccn.net/79.html)
wxPython2.8(下载地址:https://down.bccn.net/147.html)
把上面的代码保存为.pyw后缀的文件(如xxx.pyw),点击即可运行
运行效果如图:
如果不想安装Python环境直接使用该软件也可以下载直接使用:
文件MD5与SHA1查看器(绿色免安装) 下载地址:https://down.bccn.net/146.html
如果想修改源代码自己发布成上面的.exe形式,可以自己使用py2exe编译 https://down.bccn.net/148.html