0

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?

Art
  • 2,836
  • 4
  • 17
  • 34
Sanket
  • 45
  • 5
  • 1
    your encryption function is probably blocking the `.mainloop`, you probably want to do the encryption in another thread, also code should be provided in the question as text and as a [mre] – Matiiss Nov 08 '21 at 18:13
  • Does this answer your question? [How do you run your own code alongside Tkinter's event loop?](https://stackoverflow.com/questions/459083/how-do-you-run-your-own-code-alongside-tkinters-event-loop) – Matiiss Nov 08 '21 at 18:14
  • You are going for 10k iterations which will take a lot of processing and probably isn't gaining much in this amount. Anyway, cryptography takes some time anyway. You should go with a different process or at least a thread here. – Thingamabobs Nov 08 '21 at 18:36

1 Answers1

1

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.

Booboo
  • 38,656
  • 3
  • 37
  • 60
  • thanks. Could you please have a look [here](https://stackoverflow.com/questions/69911786/tkinter-progressbar-for-multiprocessing) i tried everything but it doesn't seem to work. This is the last help i need please. – Sanket Nov 10 '21 at 15:03