Python基于Tkinter編寫crc校驗工具
本篇文章,完全是用來記錄代碼用的,目的是使用Python,基于Tkinter編寫crc校驗工具。
# -*- coding: utf-8 -*-import Tkinterimport tkFileDialogWIDTH = 16TOPBIT = (1 << (WIDTH - 1))crcTable = {}class FindLocation(object): def __init__(self): #創(chuàng)建主窗口,用于容納其它組件 self.root = Tkinter.Tk() #給主窗口設(shè)置標(biāo)題內(nèi)容 self.root.title('獲取bin文件的crc校驗碼') #創(chuàng)建一個輸入框,并設(shè)置尺寸 self.default_value = Tkinter.StringVar() self.default_value.set(’請輸入bin文件全路徑’) self.ip_input = Tkinter.Entry(self.root,width=30,textvariable = self.default_value) #創(chuàng)建一個回顯列表 self.display_info = Tkinter.Listbox(self.root,width=50) #創(chuàng)建一個搜索文件的按鈕 self.getPath_button = Tkinter.Button(self.root,command = self.getPath,text = '獲取文件') #創(chuàng)建一個查詢結(jié)果的按鈕 self.result_button = Tkinter.Button(self.root,command = self.crcFast,text = '獲取校驗碼') def gui_arrang(self): self.ip_input.pack() self.display_info.pack() self.getPath_button.pack() self.result_button.pack() def getPath(self): self.fname = tkFileDialog.askopenfilename() self.default_value.set(self.fname) def crcInit(self): SHIFT = WIDTH - 8 for step in range(0,256): remainder = step << SHIFT for bit in range(8,0,-1):if remainder & TOPBIT: remainder = ((remainder << 1) & 0xFFFF) ^0x1021else: remainder = remainder <<1 crcTable[step]=remainder #print('%x'%remainder) def crc16(self,cCRC,szData,rLen): for len in range(rLen): data = (cCRC >> 8) ^ ord(szData[len]) cCRC = crcTable[data] ^ (cCRC << 8) & 0xFFFF return cCRC def crcFast(self): filePath = self.ip_input.get() tLen = 0 rLen = 0 szData = 0 cCRC = 0 self.crcInit() fp = open(filePath,’rb’) fp.seek(0,2) iFileLen = fp.tell() fp.seek(0,0) while True: if (iFileLen - tLen) < 8192:rLen = iFileLen - tLen else:rLen = 8192 szData = fp.read(rLen) cCRC = self.crc16(cCRC,szData,rLen) tLen += rLen if tLen >= iFileLen:break print 'crc is %xn' % cCRC fp.close() self.display_info.insert(0,'%x'%cCRC) self.display_info.insert(0,'this bin crc is :') def main(): #初始化對象 FL = FindLocation() #進行布局 FL.gui_arrang() #主程序執(zhí)行 Tkinter.mainloop()if __name__ == ’__main__’: main()
出差必備
買火車票、高鐵票、機票,訂酒店都打9折的出行工具TRIP,點擊注冊
到此這篇關(guān)于Python基于Tkinter編寫crc校驗工具的文章就介紹到這了,更多相關(guān)Python實現(xiàn)crc校驗內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. JavaEE SpringMyBatis是什么? 它和Hibernate的區(qū)別及如何配置MyBatis2. Python 忽略文件名編碼的方法3. python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作4. 解決vue頁面刷新,數(shù)據(jù)丟失的問題5. Java Media Framework 基礎(chǔ)教程6. android studio實現(xiàn)簡單的計算器(無bug)7. 在Mac中配置Python虛擬環(huán)境過程解析8. 利用單元測試對PHP代碼進行檢查9. python excel和yaml文件的讀取封裝10. python如何實現(xiàn)word批量轉(zhuǎn)HTML
