Я пытаюсь создать приложение, которое будет одновременно записывать звук с микрофона во время обратного отсчета (и показывать время, оставшееся в окне).Я пробовал оба модуля multiprocessing
и threading
, но окно, показывающее обратный отсчет и запись (вызывается из модуля record.py), не будет работать одновременно.
Может кто-нибудь предложить какой-нибудь способ, который может это сделать?Заранее спасибо.
Ниже мой код:
import tkinter as tk
from tkinter import *
from tkinter import ttk
import time
import record as rc #record.py is the module to record sound from mic
PRACTICETIME=120
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self,"PreSys")
self.container = tk.Frame(self, height = 1000, width =1000)
self.container.pack(side="top", fill="both", expand = True)
self.container.grid_rowconfigure(0, weight=1)
self.container.grid_columnconfigure(0, weight=1)
self.frames = {}
self.create_practicePage(PracticePage)
def create_practicePage(self,cont):
frame = PracticePage(self.container, self)
self.frames[PracticePage] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(PracticePage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class PracticePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.timeLeft = tk.Label(self,text= "")
self.timeLeft.pack()
self.remaining = 0
self.countdown(120)
rc.start_record() #function to record sound
def countdown(self, remaining = None):
if remaining is not None:
self.remaining = remaining
if self.remaining <= 0:
self.timeLeft.configure(text="お疲れ様です!")
else:
mins, secs = divmod(self.remaining,60)
mins = round(mins)
secs = round(secs)
self.timeLeft.configure(text=str(mins) +"分"+ str(secs) +"秒")
self.remaining = self.remaining - 1
self.after(1000, self.countdown)
apps = App()
apps.mainloop()