钢琴键盘绑定 python

keyboard binding in piano python

如何使用 python GUI 在钢琴中绑定键盘?

我试过使用绑定,但我不知道如何使用它。

btnCs = Button(ABC2,  height = 6, width = 6, bd = 4, text = "C#", font =('arial', 18 , 'bold'), bg = "black",  fg = "white", command = value_Cs)

我希望使用给出的代码帮助我的示例

当您按下键盘上的 a 键时,观察控制台输出 运行 您的函数。您需要用鼠标聚焦 tkinter window。 event=None 是必需的,因为绑定的回调函数通过 tkinter 事件循环(mainloop)传递了一个事件对象:

from tkinter import Tk

def play_a(event=None):
    print('Play the A key sound')

root = Tk()
root.bind('a', play_a)

root.mainloop()