简体   繁体   English

文件加密时 Tkinter 滞后

[英]Tkinter lag when file encrypting

I have made a simple encryption app, here's the code - https://codeshare.io/ZJ7qJn我做了一个简单的加密应用程序,这是代码 - 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.但是当我按下加密时,我的 tkinter 应用程序滞后并显示无响应,因此我无法在 tkinter 应用程序中按下任何内容,但它确实完成了加密过程。

Is there any way to make it lag-free.有什么办法可以让它无延迟。

Try this:尝试这个:

In function encfile replace the call to fiencdone() with:在函数encfile将调用fiencdone()替换为:

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

Add the following new function definitions after the definition of function encfile :在函数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 :最后,更改第 75 行以调用run_encfile而不是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.这将在单独的线程中运行加密,但调用fiencdone表示加密已在主线程中完成,这是必需的,因为它更新了 GUI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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