In python 2.7 I created a program with the Tkinter and Winsound modules, that is basically a simple virtual piano. What I want to do is have the note play while the button in the GUI is held down, and stop when the button is releasesd. Right now, it plays the sound after the button is released and for a specified time. Im sure this is simple but im new to programming.
import winsound
from Tkinter import *
global x
x = 250
def B():
winsound.Beep(494, x) #Frequency, Time in MS
def C():
winsound.Beep(523, x)
def A():
winsound.Beep(440, x)
def G():
winsound.Beep(784, x)
def F():
winsound.Beep(698, x)
def D():
winsound.Beep(587, x)
def E():
winsound.Beep(659, x)
root = Tk()
root.title('Piano')
root.geometry('600x600')
button1 = Button(root, text = 'A', command = A, height = '5', width = '20', fg = 'red').pack()
button2 = Button(root, text = 'B', command = B, height = '5', width = '20', fg = 'red').pack()
button3 = Button(root, text = 'C', command = C, height = '5', width = '20', fg = 'red').pack()
button4 = Button(root, text = 'D', command = D, height = '5', width = '20', fg = 'red').pack()
button5 = Button(root, text = 'E', command = E, height = '5', width = '20', fg = 'red').pack()
button6 = Button(root, text = 'F', command = F, height = '5', width = '20', fg = 'red').pack()
root.mainloop()