我做了一個簡單的加密應用程式,這是代碼 - https://codeshare.io/ZJ7qJn
但是當我按下加密時,我的 tkinter 應用程式滯后并顯示無回應,因此我無法在 tkinter 應用程式中按下任何內容,但它確實完成了加密程序。
有沒有辦法讓它無延遲?
uj5u.com熱心網友回復:
嘗試這個:
在函式encfile中將呼叫替換為fiencdone():
root.event_generate("<<encryption_done>>")
在 function 定義之后添加以下新的函式定義encfile:
def run_encfile():
from threading import Thread
root.bind('<<encryption_done>>', encryption_done)
Thread(target=encfile).start()
def encryption_done(*args):
fiencdone()
最后,將第 75 行更改為呼叫run_encfile而不是encfile:
file_enc_button = tk.Button(fibutton_frame, text='Encrypt',font='Raleway 15 bold', width=15,command=run_encfile, borderwidth=3)
這將在單獨的執行緒中運行加密,但會呼叫fiencdone在主執行緒中完成加密的信號,這是必需的,因為它更新了 GUI。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/356592.html
