【PyQT 4】pyQt实现MD5之答疑解惑
#!/usr/bin/env python#-*- coding: utf-8 -*-import sysfrom PyQt4.QtGui import *from PyQt4.QtCore import *from ctypes import *from ctypes import cdllQTextCodec.setCodecForTr(QTextCodec.codecFor
·
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from ctypes import *
from ctypes import cdll
QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
class Calc_MD5:
md5_dll = cdll.LoadLibrary("md5.dll")
def calc_md5(self, filename, val):
new_filename = c_char_p(filename)
return md5_dll.calc_md5(new_filename)
class InputDlg(QWidget):
def __init__(self, parent=None):
super(InputDlg, self).__init__(parent)
self.setWindowTitle("FileMD5")
label1 = QLabel(self.tr("文件"))
self.LineEdit1 = QLineEdit(self)
label2 = QLabel(self.tr("MD5"))
self.LineEdit2 = QLineEdit(self)
self.PushButtonFile = QPushButton(self.tr("..."))
self.PushButtonData = QPushButton(self.tr("计算"))
Layout = QGridLayout()
Layout.addWidget(label1, 0, 0)
Layout.addWidget(self.LineEdit1, 0, 1)
Layout.addWidget(self.PushButtonFile, 0, 2)
Layout.addWidget(label2, 1, 0)
Layout.addWidget(self.LineEdit2, 1, 1)
Layout.addWidget(self.PushButtonData, 2, 0)
self.setLayout(Layout)
self.connect(self.PushButtonFile, SIGNAL("clicked()"), self.openFile)
self.connect(self.PushButtonData, SIGNAL("clicked()"), self.slotData)
self.Calc = Calc_MD5()
def openFile(self):
s = QFileDialog.getOpenFileName(self, "Open file dialog", "/")
self.LineEdit1.setText(str(s))
new_filename = s
def slotData(self):
self.val = self.Calc.calc_md5()
self.LineEdit2.setText(str(self.val))
app = QApplication(sys.argv)
M = InputDlg()
M.show()
app.exec_()
更多推荐
已为社区贡献2条内容
所有评论(0)