当我按下按钮程序冻结

时间:2016-09-26 22:02:23

标签: python-2.7 tkinter

嗨我做了一个记事本来阅读文本,但是当我按下按钮时,程序冻结并开始阅读并在完成程序工作后再次

我需要能够按下按钮阅读,如果我想停止阅读我按下按钮停止enter image description here

def read_file():
    content = textPad.get('1.0', END+'-1c')
    speak (content)
def clear():
    textPad.configure(state="normal")
    textPad.delete(0,END);
def open_command():
    file = tkFileDialog.askopenfile(parent=top,mode='rb',title='Select a file')
    if file != None:
        content = file.read()
        textPad.configure(state="normal")
        textPad.insert('1.0',content)
        textPad.configure(state="disabled")
        file.close()
        return content

1 个答案:

答案 0 :(得分:0)

单线程程序一次只能做一件事。如果speak(content)需要很长时间,那么在完成之前,您将无法与GUI进行交互。

如果您需要能够中断它,则必须在另一个线程或其他进程中运行speak(content)命令。