嗨我做了一个记事本来阅读文本,但是当我按下按钮时,程序冻结并开始阅读并在完成程序工作后再次
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
答案 0 :(得分:0)
单线程程序一次只能做一件事。如果speak(content)
需要很长时间,那么在完成之前,您将无法与GUI进行交互。
如果您需要能够中断它,则必须在另一个线程或其他进程中运行speak(content)
命令。