0

how can I bind keyboard in piano using python GUI?

I tried using bind but I did not know how to use that.

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

I expect an example using the code given help me pls

progmatico
  • 4,714
  • 1
  • 16
  • 27
Noel
  • 3
  • 2

1 Answers1

2

Watch the console output running your function when you press the a key in your keyboard. You need to focus the tkinter window with the mouse. event=None is needed because the binded callback function gets passed an event object by the tkinter event loop (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()
progmatico
  • 4,714
  • 1
  • 16
  • 27
  • You are welcome @Noel, see also [here](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm) about events and binding in tkinter. – progmatico May 25 '19 at 14:53