Python Öğreniyorum 25 – Piyano nasıl yapılır tkinter
Python Öğreniyorum 25 – Piyano nasıl yapılır tkinter. Bu videomuzda tkinter ve playsound modüllerini kullanarak basit bir piyano kodlayacağız. Ayrıca videonun sonuna doğru verilen notaları otomatik çalan kısım da ekliyoruz.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
import tkinter as tk from playsound import playsound def do(event=None): b1.config(relief=tk.SUNKEN) playsound('nota-do.wav', False) b1.after(50, lambda: b1.config(relief=tk.RAISED)) def re(event=None): b2.config(relief=tk.SUNKEN) playsound('nota-re.wav', False) b2.after(50, lambda: b2.config(relief=tk.RAISED)) def mi(event=None): b3.config(relief=tk.SUNKEN) playsound('nota-mi.wav', False) b3.after(50, lambda: b3.config(relief=tk.RAISED)) def fa(event=None): b4.config(relief=tk.SUNKEN) playsound('nota-fa.wav', False) b4.after(50, lambda: b4.config(relief=tk.RAISED)) def sol(event=None): b5.config(relief=tk.SUNKEN) playsound('nota-sol.wav', False) b5.after(50, lambda: b5.config(relief=tk.RAISED)) def la(event=None): b6.config(relief=tk.SUNKEN) playsound('nota-lya.wav', False) b6.after(50, lambda: b6.config(relief=tk.RAISED)) def si(event=None): b7.config(relief=tk.SUNKEN) playsound('nota-si.wav', False) b7.after(50, lambda: b7.config(relief=tk.RAISED)) def oto(): f = open('nota.txt') s=f.readlines() def notalar(i): if i < len(s): satir=s[i].split() def nota(j): if j <len(satir): if satir[j].lower() == 'do': do() if satir[j].lower() == 're': re() if satir[j].lower() == 'mi': mi() if satir[j].lower() == 'fa': fa() if satir[j].lower() == 'sol': sol() if satir[j].lower() == 'la': la() if satir[j].lower() == 'si': si() j = j + 1 pencere.after(200, lambda: nota(j)) nota(0) i = i + 1 pencere.after(200*len(satir)+1000, lambda: notalar(i)) notalar(0) pencere = tk.Tk() pencere.title('Piyano') pencere.geometry('520x400') b1=tk.Button(pencere, text='Do', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=do) b1.place(x=50, y=20) b2=tk.Button(pencere, text='Re', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=re) b2.place(x=110, y=20) b3=tk.Button(pencere, text='Mi', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=mi) b3.place(x=170, y=20) b4=tk.Button(pencere, text='Fa', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=fa) b4.place(x=230, y=20) b5=tk.Button(pencere, text='Sol', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=sol) b5.place(x=290, y=20) b6=tk.Button(pencere, text='La', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=la) b6.place(x=350, y=20) b7=tk.Button(pencere, text='Si', font='Verdana 14 bold', bg='white', fg='black', height=10, width=3, command=si) b7.place(x=410, y=20) b8=tk.Button(pencere, text='Otomatik', font='Verdana 14 bold', bg='white', fg='black', height=1, width=10, command=oto) b8.place(x=200, y=300) pencere.bind('<a>', do) pencere.bind('<s>', re) pencere.bind('<d>', mi) pencere.bind('<f>', fa) pencere.bind('<g>', sol) pencere.bind('<h>', la) pencere.bind('<j>', si) pencere.mainloop() |