-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_dialog.py
39 lines (30 loc) · 1.3 KB
/
player_dialog.py
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
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter.messagebox import showinfo
import os
import random
class OpenFile:
def __init__(self, window):
window.title('Open Music File Dialog')
window.geometry('300x200')
open_button = ttk.Button(window, text='Open a wav file', command=self.select_file)
open_button.pack(expand=True)
random_button = ttk.Button(window, text='Play a random music clip', command=self.select_random_file)
random_button.pack(expand=True)
# set the default wav file
self.file = "music_clips/major-scale.wav"
def select_file(self):
filetypes = (('wav files', '*.wav'),)
filename = fd.askopenfilename(
title='Open a file',
initialdir='/',
filetypes=filetypes)
showinfo(message='Please close the dialog window to open the music visualizer.')
self.file = filename
def select_random_file(self):
# music_clips folder stores example music clips and music clips generated by our synthesizer
path = 'music_clips/'
list_files = os.listdir(path)
random_file = random.choice(list_files)
self.file = path + random_file
showinfo(message='Please close the dialog window to open the music visualizer.')