我正在尝试制作一个可以同时录制倒数(并在窗口显示剩余时间)的同时录制麦克风声音的应用。我已经尝试过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()