-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPyMusicPlayer.py
145 lines (109 loc) · 4.05 KB
/
PyMusicPlayer.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
import os
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
import pygame
from tkinter import ttk
from ttkthemes import themed_tk as tk
import webbrowser
#Make songs that are double-clicked, played
def selected_song(*args):
selected = listbox.curselection()
pygame.mixer.music.play(1)
updatelabel()
def closeapp(*args):
root.destroy()
def opengithub():
webbrowser.open_new("https://github.com/sketchyboi14")
def aboutpymusicplayer(*args):
messagebox.showinfo("About PyMusic Player", "PyMusic Player was built by sketchyboi14 in python. Go to https://github.com/sketchyboi14/PyMusicPlayer/issues to report issues.")
def nextsong(*args):
global index
index += 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
def prevsong(*args):
global index
index -= 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
def stopsong(*args):
pygame.mixer.music.stop()
v.set("")
def updatelabel():
global index
v.set(listofsongs[index])
def directorychooser(*args):
directory = filedialog.askdirectory(title="Select Folder")
os.chdir(directory)
for files in os.listdir(directory):
if files.endswith(".mp3"):
listofsongs.append(files)
for files in os.listdir(directory):
if files.endswith(".wav"):
listofsongs.append(files)
for files in os.listdir(directory):
if files.endswith(".ogg"):
listofsongs.append(files)
for files in os.listdir(directory):
if files.endswith(".flac"):
listofsongs.append(files)
pygame.mixer.init()
pygame.mixer.music.load(listofsongs[0])
root = tk.ThemedTk()
root.get_themes()
root.set_theme("breeze")
root.minsize(300,300)
root.title("PyMusic Player")
appicon = PhotoImage(file="icons/purphalfnote.png")
root.tk.call("wm", "iconphoto", root._w, appicon)
nextbtnicon = PhotoImage(file="icons/playbutton.png")
prevbtnicon = PhotoImage(file="icons/prevbutton.png")
stopbtnicon = PhotoImage(file="icons/stop.png")
githubbtnicon = PhotoImage(file="icons/githublogo.png")
openfoldericon = PhotoImage(file="icons/openicon.png")
closeicon = PhotoImage(file="icons/closeicon.png")
infoicon = PhotoImage(file="icons/infoicon.png")
v = StringVar()
songlabel = Label(root, textvariable=v, width=35)
listofsongs = []
index = 0
root.iconify()
messagebox.showinfo("Attention!", "Welcome to PyMusic Player. After you click OK, the file manager will open. Navigate to a folder that contains audio files such as mp3 or wav.")
root.deiconify()
directorychooser()
label = Label(root, text="Songs", font=("Meera", 10, "bold"), fg="blue")
label.pack()
listbox = Listbox(root, width=50)
listbox.pack()
reversedlist = listofsongs.reverse()
for items in listofsongs:
listbox.insert(0,items)
nextbutton = ttk.Button(root, command=nextsong, image=nextbtnicon)
nextbutton.pack(side=RIGHT)
root.bind("<Right>", nextsong)
previousbutton = ttk.Button(root, command=prevsong, image=prevbtnicon)
previousbutton.pack(side=LEFT)
root.bind("<Left>", prevsong)
stopbutton = ttk.Button(root, command=stopsong, image=stopbtnicon)
stopbutton.pack()
root.bind("<space>", stopsong)
songlabel.pack()
githubbtn = Button(root, image=githubbtnicon, command=opengithub, relief="flat")
githubbtn.pack()
menu = Menu(root)
submenu = Menu(menu, tearoff=False)
menu.add_cascade(label="File", menu=submenu, font=("Meera", 10, "bold"))
submenu.add_command(label="Open Folder", command=directorychooser, font=("Meera", 10, "bold"), accelerator="Ctrl O", compound=LEFT, image=openfoldericon)
submenu.add_command(label="Close", command=root.destroy, font=("Meera", 10, "bold"), accelerator="Ctrl W", compound=LEFT, image=closeicon)
submenu = Menu(menu, tearoff=False)
menu.add_cascade(label="Help", menu=submenu, font=("Meera", 10, "bold"))
submenu.add_command(label="About PyMusic Player", command=aboutpymusicplayer, font=("Meera", 10, "bold"), accelerator="Ctrl H", compound=LEFT, image=infoicon)
root.bind("<Control-o>", directorychooser)
root.bind("<Control-w>", closeapp)
root.bind("<Control-h>", aboutpymusicplayer)
listbox.bind("<Double-Button-1>", selected_song)
root.config(menu=menu)
root.mainloop()