简体   繁体   中英

Tkinter lag when file encrypting

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 cant press anything within the tkinter app, but it does complete the encryption process.

Is there any way to make it lag-free.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM