python - 如何解决散列时python中的内存错误
问题描述
该程序通过 GUI 获取文件。我正在为 GUI 使用 tkinter。打印目录中的文件,然后以按钮的形式打印功能的数量。每个按钮执行特定的操作。为传递的文件创建一个哈希。哈希值将打印在屏幕上。
import hashlib as hl
import tkinter as tkin
# prints the list of files on screen
def files_list():
arr= os.listdir()
row_number=next(row)
column_number=0
for i in arr:
array_lable=tkin.Label(root,text=i).grid(row=row_number,column=column_number)
column_number+=1
if column_number==5:
column_number=0
row_number=next(row)
def file_processor(file_name):
if file_name not in os.listdir():
error="file not found"
error_lable=tkin.Label(root,text=error,bg='red')
error_lable.grid(row=next(row),column=0)
file= open(file_name, 'rb')
file_content= file.read()
return file_content
def hash_printer(value,file_name):
value=value.hexdigest()
text="The hash value for {} is {}".format(file_name,value)
Lable=tkin.Label(root,text=text)
Lable.grid(row=next(row),column=0)
def md5():
file_name=inputt.get()
file_content= file_processor(file_name)
hash_value= hl.md5(file_content)
hash_printer(hash_value,file_name)
def create_button(text,function_name):
md5=tkin.Button(root,text=text,command= function_name)
md5.grid(row=button_row,column=next(column_of_button))
row=iter(list(range(100)))
column_of_button=iter(list(range(7)))
root=tkin.Tk()
inputt=tkin.Entry(root,width=65,borderwidth=5)
inputt.grid(column=0, row=next(row), columnspan=5)
files_list()
functions={md5:"MD5"}
button_row=next(row)
for key in functions:
create_button( functions[key], key)
root.mainloop()
解决方案
推荐阅读
- c++ - 来自 Box2D 库的 SetUserData,导致在 0x010110077 处引发异常
- python - 如何用pandas DataFrame中组的平均值替换组的所有值?
- java - 如何修复:无法为类 X 调用无参数构造函数:使用 Gson 为该类型注册 InstanceCreator 可能会解决此问题
- firebase - Firebase响应中ETag的含义
- tomcat - Oracle Apex 版本 4.2.0.00.27 升级到 19.1 - 旧应用程序没有 CSS,新应用程序没问题
- jquery - 选择不同的单选按钮后如何获得不同的输出?
- javascript - Three.JS 错误 - 纹理不是二的幂/无法更改纹理
- angularjs - Froala Angularjs 添加自定义按钮
- javascript - 使用 Chrome 扩展程序发送会话 Cookie
- hana - SAP Cloud Platform 试用版 - 无法打开 HDI 容器