带有gui控制台的Python pyqt文件哈希器
我试图在gui中创建一个类似控制台的文本框,让它告诉我文件夹中是否有使用相同md5哈希的图片 我真的很困惑为什么这对我不起作用。我已经尝试了很多不同的方法来做这件事,但没有什么对我有用 这是我的代码,我正在和你一起工作,当你喜欢它时,它不会给你错误,但不会工作带有gui控制台的Python pyqt文件哈希器,python,pyqt,md5,Python,Pyqt,Md5,我试图在gui中创建一个类似控制台的文本框,让它告诉我文件夹中是否有使用相同md5哈希的图片 我真的很困惑为什么这对我不起作用。我已经尝试了很多不同的方法来做这件事,但没有什么对我有用 这是我的代码,我正在和你一起工作,当你喜欢它时,它不会给你错误,但不会工作 import webbrowser, hashlib, os, sys, time, random, win32api, re , time, subprocess from PyQt4.QtCore import QSize, QTim
import webbrowser, hashlib, os, sys, time, random, win32api, re , time, subprocess
from PyQt4.QtCore import QSize, QTimer, QRect, pyqtSlot
from PyQt4.QtGui import QApplication,QLineEdit ,QGraphicsRectItem , QMainWindow, QPushButton, QWidget, QIcon, QLabel, QPainter, QPixmap, QMessageBox, QAction, QKeySequence, QFont, QFontMetrics, QMovie
from PyQt4 import QtGui
class UIWindow(QWidget):
def __init__(self, QWidget, parent=None):
super(UIWindow, self).__init__(parent)
self.resize(QSize(400, 450))
self.textbox = QLineEdit('dance',QWidget)
self.textbox.move(20, 300)
self.textbox.resize(280,300)
self.btn = QPushButton('files',self)
self.btn .resize(100, 40)
self.btn .move(260, 400)
def sesh():
for root, dirs,files in os.walk("C:\Users\Matt\Desktop\photos", topdown=True):
for name in files:
#print(os.path.join(root, name))
FileName = (os.path.join(root, name))
hasher = hashlib.md5()
with open(str(FileName), 'rb') as afile:
buf = afile.read()
hasher.update(buf)
if (hasher.hexdigest()) == '653cd1d521d8f343c998e0d568a1e5ea':
self.textbox.setText('file is here')
if (hasher.hexdigest()) == 'd41d8cd98f00b204e9800998ecf8427e':
self.textbox.setText('file is here')
if (hasher.hexdigest()) == '03c7c0ace395d80182db07ae2c30f034':
self.textbox.setText('file is here')
if (hasher.hexdigest()) == '6c0cbf5029aed0af395ac4b864c6b095':
self.textbox.setText('file is here')
else:
self.textbox.setText ("file is NOT here")
def click():
self.textbox.setText('Button clicked.' +str(sesh()))
self.btn .clicked.connect(click)
class MainWindow(QMainWindow,):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setGeometry(50, 50, 1000, 1000)
self.setFixedSize(950, 620)
self.startUIWindow()
self.setWindowIcon(QtGui.QIcon('Images\Logo.png'))
def startUIWindow(self):
self.Window = UIWindow(self)
self.setWindowTitle("pythonw")
self.setCentralWidget(self.Window)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainWindow()
sys.exit(app.exec_())
如果有人能为我做这件事,那将是令人惊讶的,我将非常感激我在这一点上完全迷失了方向。您没有从函数sesh返回任何东西 您正在sesh中设置文本,然后在单击中立即覆盖它 更改这些行:
self.textbox.setText('file is here')
致:
或者“不在这里”,你会得到你的答案
注意:可能只是网页格式,但您似乎在btn之后有一个空格:
self.btn .clicked.connect(click)
编辑:
要使输出更具描述性,请更改此部分:
if (hasher.hexdigest()) == '653cd1d521d8f343c998e0d568a1e5ea':
self.textbox.setText('file is here')
if (hasher.hexdigest()) == 'd41d8cd98f00b204e9800998ecf8427e':
self.textbox.setText('file is here')
if (hasher.hexdigest()) == '03c7c0ace395d80182db07ae2c30f034':
self.textbox.setText('file is here')
if (hasher.hexdigest()) == '6c0cbf5029aed0af395ac4b864c6b095':
self.textbox.setText('file is here')
else:
self.textbox.setText ("file is NOT here")
移交至:
output = ''
multi_files = False
if (hasher.hexdigest()) == '653cd1d521d8f343c998e0d568a1e5ea':
output += 'file1'
multi_files = True
if (hasher.hexdigest()) == 'd41d8cd98f00b204e9800998ecf8427e':
if multi_files == True:
output += ', file2'
else:
output += 'file2'
multi_files = True
if (hasher.hexdigest()) == '03c7c0ace395d80182db07ae2c30f034':
if multi_files == True:
output += ', file3'
else:
output += 'file3'
multi_files = True
if (hasher.hexdigest()) == '6c0cbf5029aed0af395ac4b864c6b095':
if multi_files == True:
output += ', file4'
else:
output += 'file4'
multi_files = True
output += ' found'
if multi_files == False:
output("no files here")
return output
并更改此行:
self.textbox.setText('Button clicked.' +str(sesh()))
致:
附加注释:如果您确实想要多行,则不能使用QLineEdit。如果您只输出文本,而您似乎正在使用QLabel,它可以是多行的。您可以将“\n”添加到需要换行符的字符串中。这并没有解决我的问题,感谢您的帮助,尽管我仍然没有得到任何帮助。我调整了一件事,现在确实奏效了。有没有办法让您知道如何在我的QLineEdit中打印多行,因为其中一个哈希不在我的文件夹中,它只是告诉我这一点其中一个文件在那里,但没有告诉我其中一个文件不在文件夹中1请说明您的调整是为了完成它-这将有助于其他人以后阅读此问题,2最简单的方法不是尝试使其多行,而是将返回值更改为更具描述性。我将编辑我的答案以提供一个示例。我的调整只是返回文件也不是这里我的草率键入:如果multi_files==False,则应该是:注意结尾的“:”。
self.textbox.setText('Button clicked.' +str(sesh()))
self.textbox.setText(str(sesh()))