Make a Working Music Player using Python|MP3 player GUI|Music player using tkinter|Pydroid3|Part 4



Note:-
You have to paste the path of image files in the code else it will display error messages.
To know where you have to paste the path of image files please watch tutorial which is present below the source code.
This is just a small part of the MUSIC PLAYER code.You will get the full code in our blog or you can also find it on our Youtube channel.

CODE:-

from tkinter import *
import tkinter as tk
from tkinter import filedialog
import pygame

root=tk.Tk()
root.geometry("1020x2180")
root.title("Music Player")
root.config(bg='white')

frame1=tk.Frame(root,bg='white')
frame1.pack()

frame2=tk.Frame(root,bg='white')
frame2.pack()

frame3=tk.Frame(root,bg='white')
frame3.pack()

frame4=tk.Frame(root,bg='white')
frame4.pack(pady=40)

frame5=tk.Frame(root,bg='#FF8BF0',borderwidth=5)
frame5.pack(pady=20)

#Playlist
#ADDING A SCROLLBAR
Title=Label(frame5,text="Your Playlist",width=35,bg='white',borderwidth=5)
Title.pack(padx=20,pady=20)
myscrollbar=Scrollbar(frame5,orient="vertical")
myscrollbar.pack(side="right",fill="y")
added_songs=Listbox(frame5,borderwidth=5,width=35)
added_songs.pack()

#Function to Add songs
def add_songs():
    songs=filedialog.askopenfilename(initialdir='/storage/emulated/0/',filetypes=(('mp3 files','*.mp3'),))
    songs=songs.replace('/storage/emulated/0/NCS/','')
    added_songs.insert(END,songs)
  
    
#TOPBAR 
Top_btn=Button(frame1,text="Add Songs",relief="raised",borderwidth=5,width=50,command=add_songs)
Top_btn.pack(expand=YES,fill=X,padx=20,pady=20)

#Timebar
time_label=Label(frame3,text="0:00")
time_label.pack(padx=20,pady=10)
#Center Image

Centerimage=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_134042.png')

#Center image placement

Centerimgbutton=Label(frame2,image=Centerimage,borderwidth=2,bg='white')
Centerimgbutton.grid(padx=50,pady=130)

#BUTTON IMAGES
img_play_btn=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_131217.png')
img_stop_btn=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_195345.png')
img_fwd_btn=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_130319.png')
img_back_btn=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_130655.png')
img_shuffle_btn=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_131516.png')
img_loop_btn=PhotoImage(file='/storage/emulated/0/pixelLab/20211111_131551.png')


#Playing Songs
def play_song():
    global added_songs
    Present_song=added_songs.get(ACTIVE)
    added_songs=f'/storage/emulated/0/NCS/{Present_song}'
    pygame.mixer.init()
    pygame.mixer.music.load(added_songs)
    pygame.mixer.music.play(loops=0)

def stop_song():
    pygame.mixer.music.stop()
    
    
#FUNCTION FOR CHANGING THE BUTTON


def change_pic(variable):
        if variable == 1:
            play_btn.configure(image=img_stop_btn)
            play_btn.configure(command=lambda variable = 0:change_pic(variable))
            root.update()
            play_song()
       
        elif variable ==0:
             play_btn.configure(image=img_play_btn)
             play_btn.configure(command=lambda variable = 1:change_pic(variable))
             stop_song()
             root.update()
           
    

#BUTTONS

shuffle_btn=Button(frame4,image=img_shuffle_btn,bg='white')
play_btn=Button(frame4,bg='white',image=img_play_btn,borderwidth=0,command=lambda variable=1 :change_pic(1))
stop_btn=Button(frame4,image=img_stop_btn,borderwidth=0,command=lambda variable=0 :change_pic(0))
fwd_btn=Button(frame4,bg='white',image=img_fwd_btn,borderwidth=0)
back_btn=Button(frame4,bg='white',image=img_back_btn,borderwidth=0)
loop_btn=Button(frame4,bg='white',image=img_loop_btn,borderwidth=0)


shuffle_btn.pack(side=LEFT,padx=70,pady=10)
back_btn.pack(side=LEFT,padx=5,pady=10)
play_btn.pack(side=LEFT,padx=5,pady=10)
fwd_btn.pack(side=LEFT,padx=5,pady=10)
loop_btn.pack(side=LEFT,padx=70,pady=10)

    


root.mainloop()
#Code ended

                                     Youtube tutorial                                     


"Hope it helped"
Have anything in mind? Let me 
know in the comment section👇
Next Post Previous Post
No Comment
Add Comment
comment url