Home > front end >  Tkinter lag when file encrypting
Tkinter lag when file encrypting

Time:11-09

I have made a simple encryption app, here's the code - https://codeshare.io/ZJ7qJn

But when I press encrypt my tkinter app lags and says Not Responding and so I can't press anything within the tkinter app, but it does complete the encryption process.

Is there any way to make it lag-free?

CodePudding user response:

Try this:

In function encfile replace the call to fiencdone() with:

    root.event_generate("<<encryption_done>>")

Add the following new function definitions after the definition of function encfile:

def run_encfile():
    from threading import Thread

    root.bind('<<encryption_done>>', encryption_done)
    Thread(target=encfile).start()

def encryption_done(*args):
    fiencdone()

Finally, change line 75 to invoke run_encfile instead of encfile:

file_enc_button = tk.Button(fibutton_frame, text='Encrypt',font='Raleway 15 bold', width=15,command=run_encfile, borderwidth=3)

This will run the encryption in a separate thread but have the call to fiencdone signaling that the encryption is complete done in the main thread, which is required since it updates the GUI.

  • Related