2016-09-26 38 views
0

嗨,我做了一個記事本讀取的文本,但是當我按下按鈕,讀取程序凍結,並開始閱讀和之後完成工作方案再次當我按下按鈕的程序凍結

我需要能夠按按鈕讀如果我想停下來閱讀我按下按鈕停止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 

回答

0

單線程程序只能做一兩件事的時間。如果speak(content)需要很長時間,那麼在完成之前,您將無法與GUI進行交互。

如果需要能夠中斷它,則必須在另一個線程或另一個進程中運行speak(content)命令。

+0

你的意思是在其他線程運行命令,並終止它,當我需要停止這是唯一的方式 –

+0

好吧我做到了,它的工作謝謝你 –

相關問題