Tcl_AsyncDelete:异步处理程序被错误的线程删除中止(核心转储)

时间:2019-05-03 07:29:29

标签: python-3.x multithreading tkinter

在杀死Tkinter时(在多线程中将其删除),问题正在发生

将tkinter导入为tk 导入线程 导入pyaudio 进口波 导入Speech_recognition作为sr 导入时间 将tkinter导入为tk

全局停止 停止= 0

全局计数 计数= 0

def audiorecord():

FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"

audio = pyaudio.PyAudio()

stream = audio.open(format=FORMAT, channels=CHANNELS,
                rate=RATE, input=True,
                frames_per_buffer=CHUNK)
frames = []
global stop
while stop == 0:
    data = stream.read(CHUNK)
    frames.append(data)

print("finished recording")
stream.stop_stream()
stream.close()
audio.terminate()
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()

def stop():     全局停止,根     停止= 1     尝试:         root.quit()     例外,例如e:         打印(e)

尝试:     def tkinter():

    global root
    root = tk.Tk()
    btn12 = tk.Button(root, text = "stop recording", command=stopped)
    btn12.pack()    
    root.mainloop()

ISSUUE OCCUR HERER

    root.destroy()

例外,例如e:     打印(e)

尝试:

#start from here ------ multithreading

recording = threading.Thread(target=audiorecord, args=())
stops = threading.Thread(target=tkinter, args=())

recording.start()
stops.start()

recording.join()
stops.join()

例外,例如e:     打印(“不成功”,e)

1 个答案:

答案 0 :(得分:-1)

使用withdraw()函数

tkinter具有内置功能