我正在制作一个显示钢琴画面的GUI,当用户按下某些按钮时,它会弹奏钢琴音符。
import tkinter
from tkinter import *
from pydub import AudioSegment
import winsound, sys
import pyglet
//creates a window with a picture of a piano on it
root = Tk()
photo = PhotoImage(file = "piano.png")
label = Label(root, image = photo)
label.pack()
//when the left arrow key is pressed I want it to play audio of a c note on a piano
def leftkey(event):
print("pressed")
cnote = pyglet.resource.media("C:\\Users\\Ben\\Downloads\\cnote.mp3")
cnote.play()
pyglet.app.run()
root.bind('<Left>', leftkey)
root.focus_set()
root.pack()
root.mainloop()
答案 0 :(得分:0)
在文档中,这就是它所说的:
cnote = pyglet.media.load('cnote.mp3', streaming=False)
cnote.play()
来源: http://www.pyglet.org/doc/programming_guide/simple_audio_playback.html