Program lock when executing function. Tkinter + Python3

Asked

Viewed 257 times

0

It is the following I created a simple program to break md5 numeric, but the same lock when I click on descrypter and it only works again when it finds the hash, but it is locked until finding and has a hash like the hash md5 of '81748856' that takes 5 minutes, and it gets stuck all the time has to make it not lock and perform 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()
  • addendum: the command should be decrypt instead of Decrypter, given the function name.

  • Valew. by the remark.

1 answer

0


It is necessary to call root.update() from time to time to update the graphical screen of tkinter... If you don’t call this function once in a while, python will only be calculating md5 within its loop, and Tkinter won’t have time to update the screen... Then windows will find that the program crashed and will mark the window as "Not responding".

One way is to put inside your loop:

while True:
    root.update()
    # ... resto do código aqui ...
  • Valew.. Solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.