Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@
from tkinter import filedialog
from pygame import mixer

# Initialize the User Interface as Tkinter window
root = Tk()
root.title("Groovy Music Player")
root.geometry("485x700+290+10")
root.configure(background='#333333')
root.resizable(False, False)
mixer.init()

# Global variables
music_paused = False

current_music = None

# Function to add music to the playlist
def AddMusic():
path = filedialog.askdirectory()
if path:
os.chdir(path)
songs = os.listdir(path)

# Add only .mp3 files to the playlist
for song in songs:
if song.endswith(".mp3"):
if song.endswith(".mp3") or song.endswith(".wav"):
Playlist.insert(END, song)

# Function to play or pause music
def PlayPauseMusic():
global music_paused, current_music
if not current_music:
Expand All @@ -39,17 +43,21 @@ def PlayPauseMusic():
mixer.music.pause()
music_paused = True

# Function to stop music
def StopMusic():
global current_music
mixer.music.stop()
current_music = None

# Create the lower frame
lower_frame = Frame(root, bg="#FFFFFF", width=485, height=180)
lower_frame.place(x=0, y=400)

# Set the application icon
image_icon = PhotoImage(file="logo.png")
root.iconphoto(False, image_icon)

# Create GIF animation
frameCnt = 30
frames = [PhotoImage(file='best.gif', format='gif -index %i' % (i)) for i in range(frameCnt)]

Expand All @@ -62,34 +70,38 @@ def update(ind):
root.after(40, update, ind)

label = Label(root)
label.place(x=0, y=0)
label.grid(row=0, column=0, columnspan=5)
root.after(0, update, 0)

# Create play/pause button
ButtonPlayPause = PhotoImage(file="play.png")
Button(root, image=ButtonPlayPause, bg="#FFFFFF", bd=0, height=60, width=60,
command=PlayPauseMusic).place(x=215, y=487)
Button(root, image=ButtonPlayPause, bg="#FFFFFF", bd=0, height=60, width=60, command=PlayPauseMusic).place(x=215, y=487)

# Create stop button
ButtonStop = PhotoImage(file="stop.png")
Button(root, image=ButtonStop, bg="#FFFFFF", bd=0, height=60, width=60,
command=StopMusic).place(x=315, y=487)
Button(root, image=ButtonStop, bg="#FFFFFF", bd=0, height=60, width=60, command=StopMusic).place(x=315, y=487)

# Create volume button
Buttonvolume = PhotoImage(file="volume.png")
Button(root, image=Buttonvolume, bg="#FFFFFF", bd=0, height=60, width=60,
command=mixer.music.unpause).place(x=115, y=487)
Button(root, image=Buttonvolume, bg="#FFFFFF", bd=0, height=60, width=60, command=mixer.music.unpause).place(x=115, y=487)

# Create menu label
Menu = PhotoImage(file="menu.png")
Label(root, image=Menu).place(x=0, y=580, width=485, height=120)

# Create the music playlist
Frame_Music = Frame(root, bd=2, relief=RIDGE)
Frame_Music.place(x=0, y=585, width=485, height=100)

Button(root, text="Browse Music", width=59, height=1, font=("calibri",
12, "bold"), fg="Black", bg="#FFFFFF", command=AddMusic).place(x=0, y=550)
# Create a button to browse music
Button(root, text="Browse Music", width=59, height=1, font=("calibri", 12, "bold"), fg="Black", bg="#FFFFFF", command=AddMusic).place(x=0, y=550)

# Create a scrollbar for the playlist
Scroll = Scrollbar(Frame_Music)
Playlist = Listbox(Frame_Music, width=100, font=("Times new roman", 10), bg="#333333", fg="grey", selectbackground="lightblue", cursor="hand2", bd=0, yscrollcommand=Scroll.set)
Scroll.config(command=Playlist.yview)
Scroll.pack(side=RIGHT, fill=Y)
Playlist.pack(side=RIGHT, fill=BOTH)

# Start the main application loop
root.mainloop()