1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import tkinter as tk
import winsound
root = tk.Tk()
root.title('petit piano')
root.geometry('650x250+10+10')
gen_b = [3,5,7,8,10,12,14,15,17,19,20,22,24,26,27,29,31,32,34,36,38]
gen_n = [4,6,-1,9,11,13,-1,16,18,-1,21,23,25,-1,28,30,-1,33,35,37]
freq = f12 = 0 ; f0 = 220
tab_freqs = []
for ai in range(39): # Construction tableau TM
if 0 <= ai < 12: la = f0
elif 24 > ai > 11: la = f0*2
elif 36 > ai > 23: la = f0*4
elif ai > 35: la = f0*8
f1 = la/2 ; f2 = f1/12
freq=f12*f2+f1 # Calcul fréquence
tab_freqs.append(freq) # Tableau en écriture TM
f12+=1
if f12 > 11:
f12 = 0
def piano_b(m):
duration=200
freqhtz = int(tab_freqs[gen_b[m]])
winsound.Beep(freqhtz, duration)
def piano_n(m):
duration=200
freqhtz = int(tab_freqs[gen_n[m]])
winsound.Beep(freqhtz, duration)
btbs = []
for x in range(21):
btb = tk.Button(text=x, height=10, width=3, bg='ivory', command=lambda m=x: piano_b(m), relief="groove")
btb.place(x = 30*x, y = 30, anchor='nw')
btbs.append(btb)
o = 0
btns = []
for x in range(21):
if o == 2 or o == 6:
pass
else:
btn = tk.Button(text=x, height=5, width=2, bg='black',command=lambda m=x: piano_n(m), relief="groove")
btn.place(x = 30*x+15, y = 30, anchor='nw')
btns.append(btn)
o += 1
if o > 6:
o = 0
tk.mainloop() |
Partager