Program crash when executing the function. Tkinter + Python3

0

This is the following I created a simple program to break numeric md5, but the same hangs when I click on descrypter and it only works again when it finds the hash, but it gets stuck until it finds and has hash like hash md5 of '81748856' which takes 5 minutes, and it gets stuck all the time has how do it not lock and execute function?

from tkinter import *
root=Tk()
def decripter():
    from hashlib import md5
    import time
    a=str(h.get()).strip()
    if len(a)==32 and a.isdigit()==False and a.isalpha()==False and a.isalnum()==True:
        pass
    elif len(a) <32:
        lab1["text"]=f"\n\nTá faltando {32 - len(a)} caracteres!"
        lab1["font"]="Arial 9 bold"
        return
    else:
        lab1["text"]="\n\nTem certeza que isso é um MD5(number)?"
        lab1["font"]="Arial 9 bold"
        return
    inicio = time.time()
    n=0
    while(True):
        d= md5(str(n).encode()).hexdigest()
        if int((time.time()-inicio)) > 300:
            lab1["text"]=f"\nO tempo limite de {int(time.time()-inicio)}s se esgotou, a string não foi detectada!"
            lab1["font"]="Arial 9 bold"
            return
        if d==a:
            lab1["text"]=f"\nProcurando isso? '{n}'"
            lab1["font"]="Arial 11 bold"
            break
        else:
            n+=1

root.geometry("500x180")

root.title("Decry(MD5(num)) v1.0")

lab=Label(root, font="Arial 9 bold" , text="Bem vindo ao Decry(MD5(num)) na atual versão '1.0' \nO proposito principal desse programa é 'Descriptografar' hash Md5(number)\n\n").pack()


h=Entry(root, width=40,font="Arial 12 bold")
h.pack()
Button(root, text='Decrypter', command=decrypter).pack()
lab1=Label(root, font="Arial 9 bold" , text="\n\nTodos os direitos reservados a Code Ghost.")
lab1.pack()
root.mainloop()
    
asked by anonymous 18.10.2018 / 18:18

1 answer

0

It is necessary to call root.update() from time to time to update the graph screen of tkinter ... If you do not call this function from time to time, python will only be calculating md5 within your loop, and the tkinter will not have time to update the screen ... Then windows will find that the program has locked and will mark the window as "Not responding".

One way is to put it inside your loop:

while True:
    root.update()
    # ... resto do código aqui ...
    
18.10.2018 / 19:56