python-3.x - 如何从 tkinter 中的按钮停止功能
问题描述
我正在尝试在 ffmpeg 的帮助下从 python 中的麦克风录制音频。
通过使用它,我可以录制语音,但是如何通过单击按钮来停止此功能。
为了阻止这种情况,我现在强制终止 IDLE。
import os
import subprocess
import tkinter as tk
from tkinter import *
root = Tk()
os.chdir('C://Users/ravir/desktop/')
def recording_voice():
global p
p=subprocess.Popen('ffmpeg -f dshow -i audio="Microphone (2- High Definition Audio Device)" sample.mp3' )
def stop_rec(): # ho to stop this ???
p.terminate()
rec_btn = Button(text='Start Recording', width=20, command=recording_voice)
rec_btn.pack()
stop_btn = Button(text='Stop Recording', width=20, command=stop_rec)
stop_btn.pack()
root.mainloop()
解决方案
推荐阅读
- arrays - 如何以选定的维度对数组进行切片?
- excel - 用于查看绘图上不同数据的 MS Excel 下拉菜单
- python-sphinx - 可以将 Sphinx 的 extlinks 扩展配置为显示 url 吗?
- azure - 当容器之一终止时停止容器实例组
- node.js - 何时将用户输入写入数据库?
- c++ - STM32 引脚 B0 用作输入,但 B1 不用作
- javascript - 在 React 中克隆整个状态对象会导致副作用吗?
- inheritance - Rust 中的方法覆盖替代方案
- python - 检索每个一行中的 html 文件
- django - 使用 django-rest-framework-gis 将外键对象序列化为 geojson 时出错