V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
alphab
V2EX  ›  Python

Python3 在 PyCharm 中 运行时如何设置播放提示音?

  •  
  •   alphab · 2017-11-14 09:42:14 +08:00 · 3738 次点击
    这是一个创建于 2355 天前的主题,其中的信息可能已经有所发展或是发生改变。
    运行环境:Python3.6 ,MacOS 10.12 ,IDE:PyCharm 2017.2.4


    在 PyCharm 上运行 python3 代码,使用 pygame 设置提示音时,每次都会「自动弹出一个窗口」来播放提示音,直到程序运行结束,弹出的窗口才会自动关闭。

    有没有什么方法,能让提示音直接播放,而不是弹出一个类似播放器的窗口来播放?
    3 条回复    2017-11-19 12:50:56 +08:00
    alphab
        1
    alphab  
    OP
       2017-11-14 17:25:35 +08:00
    有人知道吗?
    Liyuu
        2
    Liyuu  
       2017-11-18 07:11:40 +08:00
    可以试试 subprocess

    import subprocess
    audio_file = "/full/path/to/audio.wav"
    return_code = subprocess.call(["afplay", audio_file])


    出处: https://stackoverflow.com/questions/3498313/how-to-trigger-from-python-playing-of-a-wav-or-mp3-audio-file-on-a-mac
    alphab
        3
    alphab  
    OP
       2017-11-19 12:50:56 +08:00
    @Liyuu 真的可以了,谢谢🙏
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 14:37 · PVG 22:37 · LAX 07:37 · JFK 10:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.