加密大文件时,tkinter GUI挂起

时间:2015-11-18 07:31:50

标签: python encryption tkinter hang

用户导入文本文件后,会在scrolledtext上显示。然后使用翻译器加密并显示在另一个滚动文本上,如下所示:

import tkinter 
from tkinter import * 
from tkinter import ttk 
from tkinter.ttk import * 
from tkinter.filedialog import askopenfile 
from tkinter.filedialog import askopenfilename
from tkinter.scrolledtext import *

letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

encryption_code = 'LFWOAYUISVZMNXPBDCRJTQEGHK'

letters += letters.lower() 
encryption_code += encryption_code.lower()

enc = dict(zip(letters,encryption_code))

window = tkinter.Tk()

style = ttk.Style(window)
style.configure("BW.TLabel")

import_frame = tkinter.Frame(window)

def import_txt():
    global import_list    
    file_name = askopenfilename(filetypes=[("Text files","*.txt")]) 

    import_list = [] 

    with open(file_name, 'r') as f:
        import_list = f.readlines() 
        encrypttxt.pack()
    f.close() 

def encrypt_txt():
    global letters
    global encryption_code
    global import_list
    global translated
    pre = "".join(import_list)
    translated = "".join([i.translate(str.maketrans(letters, encryption_code)) for i in import_list]) 
    display_txt.insert('insert', translated) 
    precrypt.insert('insert', pre)
    display_txt.pack(side=RIGHT)
    precrypt.pack(side=LEFT)

display_txt = tkinter.scrolledtext.ScrolledText(import_frame)
encrypttxt = ttk.Button(import_frame, text="Encrypt", command=encrypt_txt)
precrypt = tkinter.scrolledtext.ScrolledText(import_frame)
start = ttk.Button(window, text="START", command=import_txt)
start.pack()
import_frame.pack()

window.mainloop()

我的问题是程序在导入和加密大文件时挂起。文件越大,挂起的时间就越长。

0 个答案:

没有答案