猫史档案馆


【Python作品分享】键盘音效【作品秀】

用户:C小YC小Y查看:0 回复:0 评论:0 创建时间:2023-01-16T11:58:55


【作品展示】

center_image

 

【作品介绍】

可以让你的键盘发出音效(自定义)

教程代码里有

 

【作品源代码】

import keyboard
from playsound import playsound
import threading
import os
import random

def play():
    result = random.randint(0,len(sound_list) - 1)
    playsound('sound/' + sound_list[result])

def Press(x):
    if x.event_type == 'down':
        threading.Thread(target=play).start()

if __name__=='__main__':
    sound_list = os.listdir('./sound')
    keyboard.hook(Press)
    keyboard.wait()

#作品使用方式
#在文件夹里创建命名为 “sound” 的文件夹 并和此作品放在一起
#“sound”文件夹里是放要播放音频  ( 最好是mp3类型的)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页