forked from Euno257/PlayNow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
175 lines (132 loc) · 4.32 KB
/
test.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import os
from tkinter.filedialog import askdirectory
from tkinter import *
import tkinter.messagebox
from pygame import mixer
from mutagen.id3 import ID3
from tkinter import ttk
from ttkthemes import themed_tk as tk
#creating a root window
root = tk.ThemedTk() # Creates an object for the ThemedTk wrapper for the normal Tk class
root.get_themes() # Returns a list of all themes that can be set
root.set_theme("aquativo")
root.title("PlayNow")
root.iconbitmap(r'title.ico')
#creating lists to store songs from playlist
lists = []
real = []
#topframe stores label and listbox while middleframe stores play,pause buttons
topframe= Frame(root)
topframe.pack()
middleframe= Frame(root)
middleframe.pack(pady=15,padx=15)
index = 0
songname = 0
text = ttk.Label(topframe, text='feel the beat')
text.pack(pady=10)
v = StringVar()
songlabel = Label(root, textvariable=v, width=35)
songlabel.pack()
#creating a listbox inside the topframe
listbox = Listbox(topframe)
listbox.pack()
#defining functions
def directorys():
directory = askdirectory()
os.chdir(directory)
for files in os.listdir(directory):
if files.endswith(".mp3"):
realdir = os.path.realpath(files)
audio = ID3(realdir)
real.append(audio['TIT2'].text[0])
lists.append(files)
real.reverse()
for items in real:
listbox.insert(0, items)
real.reverse()
# initializing_the_mixer
mixer.init()
def play():
try:
paused #paused is initialised
except:
try:
mixer.music.load(lists[index])
mixer.music.play()
statusbar['text']='Playing '+''+os.path.basename(lists[index])
except:
tkinter.messagebox.showerror('File not found', 'Add a song to play')
else:
mixer.music.unpause()
statusbar['text'] = 'Playing '+''+os.path.basename(lists[index])
def update():
global index
global songname
v.set(real[index])
def stop():
try:
global paused
paused= TRUE
mixer.music.pause()
statusbar['text'] = 'Playing paused'
v.set("")
except:
tkinter.messagebox.showerror('File not found', 'Add a song to play')
def next():
try:
global index
index +=1
mixer.music.load(lists[index])
mixer.music.play()
statusbar['text']= 'Playing '+''+os.path.basename(lists[index])
update()
except:
tkinter.messagebox.showerror('File not found', 'Add a song to play')
def prv():
try:
global index
index -= 1
mixer.music.load(lists[index])
mixer.music.play()
update()
statusbar['text'] = 'Playing ' + '' + os.path.basename(lists[index])
except:
tkinter.messagebox.showerror('File not found', 'Add a song to play')
def setvol(val):
volume = int(val)/100 #typecasting(string into int)
mixer.music.set_volume(volume)
def about():
tkinter.messagebox.showinfo('version 1.0','Developed by developers from Bangalore,India')
#adding buttons to GUI
playphoto = PhotoImage(file='play.png')
playbtn = ttk.Button(middleframe, image=playphoto,command=play)
playbtn.grid(row=0,column=1,padx=3)
stopphoto = PhotoImage(file='pause.png')
stopbtn = ttk.Button(middleframe, image=stopphoto, command=stop)
stopbtn.grid(row=0,column=2,padx=3)
nextphoto = PhotoImage(file='next.png')
nextbtn = ttk.Button(middleframe, image=nextphoto, command=next)
nextbtn.grid(row=0,column=3,padx=3)
prvphoto = PhotoImage(file='back.png')
prvbtn = ttk.Button(middleframe, image=prvphoto, command=prv)
prvbtn.grid(row=0,column=0,padx=3)
addbtn= ttk.Button(topframe,text='+ADD',command= directorys)
addbtn.pack()
#volume control
scale = Scale(root, from_=0, to=100, orient=HORIZONTAL, command=setvol)
scale.set(55)
mixer.music.set_volume(55)
scale.pack(pady=10)
#creating a menubar
menubar= Menu(root)
root.config(menu=menubar)
submenu =Menu (menubar, tearoff=0)
menubar.add_cascade(label='File', menu=submenu)
submenu.add_command(label='Browse', command= directorys)
submenu.add_command(label='Exit',command=root.destroy)
submenu =Menu (menubar, tearoff=0)
menubar.add_cascade(label='Help',menu=submenu)
submenu.add_command(label='About us',command= about)
statusbar=Label(root,text="Playnow",relief=SUNKEN, anchor=W)
statusbar.pack(side=BOTTOM, fill=X,anchor=W)
root.mainloop()