|
1 | 1 | from tkinter import * |
2 | 2 | import tkinter as tk |
3 | | -import winsound |
4 | 3 | from PIL import ImageTk, Image |
5 | 4 | from playsound import playsound |
6 | | - |
| 5 | +root = tk.Tk() |
| 6 | +root.geometry('700x300') |
| 7 | +root.title("piano") |
| 8 | +root.maxsize(700,300) |
| 9 | +root.minsize(700,300) |
| 10 | +root['bg']="white" |
| 11 | +icon = ImageTk.PhotoImage(Image.open('piano.png')) |
| 12 | +icon_label = Label(root,image=icon) |
| 13 | +icon_label.place(x=295,y=10) |
| 14 | +frame1 = Frame(root,width=700,height=198,bg="white") |
| 15 | +frame1.place(x=0,y=100) |
7 | 16 | class piano(): |
8 | | - |
9 | | - def button1(self): |
10 | | - winsound.Beep(1000,100) |
11 | | - def button2(self): |
12 | | - playsound('piano11.mp3') |
13 | | - def button3(self): |
14 | | - playsound('piano12.mp3') |
15 | | - def button4(self): |
16 | | - playsound('piano13.mp3') |
17 | | - def button5(self): |
18 | | - playsound('piano14.mp3') |
19 | | - def button6(self): |
20 | | - playsound('piano15.mp3') |
21 | | - def button7(self): |
22 | | - playsound('piano16.mp3') |
23 | | - def button8(self): |
24 | | - playsound('piano17.mp3') |
25 | | - def button9(self): |
26 | | - playsound('piano18.mp3') |
27 | | - def button10(self): |
28 | | - playsound('piano19.mp3') |
29 | | - def button11(self): |
30 | | - playsound('piano110.mp3') |
31 | | - def button12(self): |
32 | | - playsound('piano111.mp3') |
33 | | - def button13(self): |
34 | | - playsound('piano112.mp3') |
35 | | - def button14(self): |
36 | | - playsound('piano113.mp3') |
37 | | - def button15(self): |
38 | | - playsound('piano114.mp3') |
39 | | - def button16(self): |
40 | | - playsound('piano115.mp3') |
41 | | - def button17(self): |
42 | | - playsound('piano116.mp3') |
43 | | - def button18(self): |
44 | | - playsound('piano117.mp3') |
45 | | - def button19(self): |
46 | | - playsound('piano118.mp3') |
47 | | - def button20(self): |
48 | | - playsound('piano119.mp3') |
49 | | - def button21(self): |
50 | | - playsound('piano120.mp3') |
51 | | - def button22(self): |
52 | | - playsound('piano121.mp3') |
53 | | - def button23(self): |
54 | | - playsound('piano122.mp3') |
55 | | - |
56 | | - |
57 | | - |
58 | | - def __init__(self): |
59 | | - self.root = tk.Tk() |
60 | | - self.root.geometry('700x300') |
61 | | - self.root.title("piano") |
62 | | - self.root.maxsize(700,300) |
63 | | - self.root.minsize(700,300) |
64 | | - self.root['bg']="white" |
65 | | - |
66 | | - |
67 | | - self.icon = ImageTk.PhotoImage(Image.open('piano.png')) |
68 | | - |
69 | | - self.icon_label = Label(self.root,image=self.icon) |
70 | | - self.icon_label.place(x=295,y=10) |
71 | | - |
72 | | - self.frame1 = Frame(self.root,width=700,height=198,bg="white") |
73 | | - self.frame1.place(x=0,y=100) |
74 | | - |
75 | | - self.button1 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button1,cursor="hand2") |
76 | | - self.button1.place(x=0,y=0) |
77 | | - |
78 | | - |
79 | | - self.button2 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button2,cursor="hand2") |
80 | | - self.button2.place(x=30,y=0) |
81 | | - |
82 | | - self.button3 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button3,cursor="hand2") |
83 | | - self.button3.place(x=60,y=0) |
84 | | - |
85 | | - self.button4 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button4,cursor="hand2") |
86 | | - self.button4.place(x=90,y=0) |
87 | | - |
88 | | - self.button5 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button5,cursor="hand2") |
89 | | - self.button5.place(x=120,y=0) |
90 | | - |
91 | | - self.button6 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button6,cursor="hand2") |
92 | | - self.button6.place(x=150,y=0) |
93 | | - |
94 | | - self.button7 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button7,cursor="hand2") |
95 | | - self.button7.place(x=180,y=0) |
96 | | - |
97 | | - self.button8 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button8,cursor="hand2") |
98 | | - self.button8.place(x=210,y=0) |
99 | | - |
100 | | - self.button9 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button9,cursor="hand2") |
101 | | - self.button9.place(x=240,y=0) |
102 | | - |
103 | | - self.button10 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button10,cursor="hand2") |
104 | | - self.button10.place(x=270,y=0) |
105 | | - |
106 | | - self.button11 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button11,cursor="hand2") |
107 | | - self.button11.place(x=300,y=0) |
108 | | - |
109 | | - self.button12 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button12,cursor="hand2") |
110 | | - self.button12.place(x=330,y=0) |
111 | | - |
112 | | - self.button13 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button13,cursor="hand2") |
113 | | - self.button13.place(x=360,y=0) |
114 | | - |
115 | | - self.button14 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button14,cursor="hand2") |
116 | | - self.button14.place(x=390,y=0) |
117 | | - |
118 | | - self.button15 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button15,cursor="hand2") |
119 | | - self.button15.place(x=420,y=0) |
120 | | - |
121 | | - self.button16 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button16,cursor="hand2") |
122 | | - self.button16.place(x=450,y=0) |
123 | | - |
124 | | - self.button17 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button17,cursor="hand2") |
125 | | - self.button17.place(x=480,y=0) |
126 | | - |
127 | | - self.button18 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button18,cursor="hand2") |
128 | | - self.button18.place(x=510,y=0) |
129 | | - |
130 | | - self.button19 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button19,cursor="hand2") |
131 | | - self.button19.place(x=540,y=0) |
132 | | - |
133 | | - self.button20 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button20,cursor="hand2") |
134 | | - self.button20.place(x=570,y=0) |
135 | | - |
136 | | - self.button21 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button21,cursor="hand2") |
137 | | - self.button21.place(x=600,y=0) |
138 | | - |
139 | | - self.button22 = Button(self.frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=self.button22,cursor="hand2") |
140 | | - self.button22.place(x=630,y=0) |
141 | | - |
142 | | - self.button23 = Button(self.frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=self.button23,cursor="hand2") |
143 | | - self.button23.place(x=660,y=0) |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - self.root.mainloop() |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
| 17 | + def PianoSound(self,sound): |
| 18 | + playsound(f'Piano{sound}.mp3') |
| 19 | + def __init__(self,index): |
| 20 | + self.index = index |
| 21 | + if self.index%2 != 0: |
| 22 | + Button(frame1,padx=10,pady=100,bg="black",fg="white",relief=RAISED,borderwidth=3,command=lambda:self.PianoSound(self.index),cursor="hand2").grid(row=0,column=self.index) |
| 23 | + else: |
| 24 | + Button(frame1,padx=10,pady=100,bg="white",fg="black",relief=RAISED,borderwidth=2,command=lambda:self.PianoSound(self.index),cursor="hand2").grid(row=0,column=self.index) |
160 | 25 | if __name__ == '__main__': |
161 | | - |
162 | | - piano() |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
| 26 | + for i in range(1,24): |
| 27 | + piano(i) |
| 28 | +root.mainloop() |
0 commit comments