Amazing-Python-Scripts

Форк
0
118 строк · 3.5 Кб
1
from tkinter import *
2
from playsound import playsound
3
from threading import Thread
4

5

6
class padSound:
7
    def __init__(self, soundLocation):
8
        self.soundLocation = soundLocation
9

10
    def given_sound(self):
11
        playsound(self.soundLocation)
12

13
    def play_sound(self, event):
14
        sound = Thread(target=self.given_sound)
15
        sound.start()
16

17

18
# All the locations of the sounds
19
kickLocation = './Beat-Board/Sounds/Kick.wav'
20
hiHatLocation = './Beat-Board/Sounds/hiHat.wav'
21
snareLocation = './Beat-Board/Sounds/snare.wav'
22
pad1Location = './Beat-Board/Sounds/Pad1.wav'
23
pad2Location = './Beat-Board/Sounds/Pad2.wav'
24
pad3Location = './Beat-Board/Sounds/Pad3.wav'
25
pad4Location = './Beat-Board/Sounds/Pad4.wav'
26
pad5Location = './Beat-Board/Sounds/Pad5.wav'
27
pad6Location = './Beat-Board/Sounds/Pad6.wav'
28

29
# Create drum objects
30
kickDrum = padSound(kickLocation)
31
hiHatDrum = padSound(hiHatLocation)
32
snareDrum = padSound(snareLocation)
33

34
# Create pad objects
35
pad1 = padSound(pad1Location)
36
pad2 = padSound(pad2Location)
37
pad3 = padSound(pad3Location)
38
pad4 = padSound(pad4Location)
39
pad5 = padSound(pad5Location)
40
pad6 = padSound(pad6Location)
41

42

43
def create_layout():
44

45
    # Creates the Frame
46
    frame_a = Frame(master=main_window, width=500, height=500, bg="black")
47
    frame_a.grid(rowspan=3, columnspan=3)
48
    frame_a.focus_set()
49

50
    # Creates the Buttons
51
    # ------------------------------------------------
52
    # Kick Button
53
    kickButton = Button(text="Kick", height=5, width=10)
54
    frame_a.bind('q', kickDrum.play_sound)
55
    kickButton.bind("<Button-1>", kickDrum.play_sound)
56

57
    # Hi-hat Button
58
    hihatButton = Button(text="Hi-Hat", height=5, width=10)
59
    frame_a.bind('w', hiHatDrum.play_sound)
60
    hihatButton.bind("<Button-1>", hiHatDrum.play_sound)
61

62
    # Snare Button
63
    snareButton = Button(text="Snare", height=5, width=10)
64
    frame_a.bind('e', snareDrum.play_sound)
65
    snareButton.bind("<Button-1>", snareDrum.play_sound)
66

67
    # -------------------------------------------------
68
    # Pad 1
69
    pad1Button = Button(text="Pad 1", height=5, width=10)
70
    frame_a.bind('a', pad1.play_sound)
71
    pad1Button.bind("<Button-1>", pad1.play_sound)
72

73
    # Pad 2
74
    pad2Button = Button(text="Pad 2", height=5, width=10)
75
    frame_a.bind('s', pad2.play_sound)
76
    pad2Button.bind("<Button-1>", pad2.play_sound)
77

78
    # Pad 3
79
    pad3Button = Button(text="Pad 3", height=5, width=10)
80
    frame_a.bind('d', pad3.play_sound)
81
    pad3Button.bind("<Button-1>", pad2.play_sound)
82

83
    # -------------------------------------------------
84
    # Pad 4
85
    pad4Button = Button(text="Pad 4", height=5, width=10)
86
    frame_a.bind('z', pad4.play_sound)
87
    pad4Button.bind("<Button-1>", pad4.play_sound)
88

89
    # Pad 5
90
    pad5Button = Button(text="Pad 5", height=5, width=10)
91
    frame_a.bind('x', pad5.play_sound)
92
    pad5Button.bind("<Button-1>", pad5.play_sound)
93

94
    # Pad 6
95
    pad6Button = Button(text="Pad 6", height=5, width=10)
96
    frame_a.bind('c', pad6.play_sound)
97
    pad6Button.bind("<Button-1>", pad6.play_sound)
98
    # -------------------------------------------------
99

100
    # Display Buttons
101
    kickButton.grid(row=0)
102
    hihatButton.grid(row=0, column=1)
103
    snareButton.grid(row=0, column=2)
104

105
    pad1Button.grid(row=1)
106
    pad2Button.grid(row=1, column=1)
107
    pad3Button.grid(row=1, column=2)
108

109
    pad4Button.grid(row=2)
110
    pad5Button.grid(row=2, column=1)
111
    pad6Button.grid(row=2, column=2)
112

113

114
main_window = Tk()
115
main_window.resizable(False, False)
116
main_window.title('Beat Board')
117
create_layout()
118
main_window.mainloop()
119

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.