Making play, next , previous buttons functions| Vid 5| Music player in android tkinter|@binarycup

Опубликовано: 27 Март 2026
на канале: BINARY CUP
54
7

Source code

------------------------------------------------------------------------
from pygame import mixer
from tkinter import*
from tkinter.simpledialog import*
from tkinter.messagebox import*
import os, random

mixer.init()
root=Tk()
root.minsize(400,400)
music_file_path=[]
music_file_name=[]


top_frame=Frame(root)
central_frame=Frame(root)
bottom_frame=Frame(root)

#Packing frames
top_frame.pack(pady=5,padx=5)
central_frame.pack(pady=5)
bottom_frame.pack(padx=5,pady=5)


logo=Label(top_frame,text="Your name")
logo.pack()

for folder,sub_folder,file in os.walk("/storage/emulated/0/Music"):
for i in file:
if ".mp3" in i:
music_file_name.append(i)
music_file_path.append(folder+"/"+i)

song_box=Listbox(central_frame,width=41,height=27)
s=Scrollbar(central_frame,orient='vertical')
#Configuring scroll bar
song_box.config(yscrollcommand=s.set)
s.config(command=song_box.yview)


for i in music_file_name:
song_box.insert(END,i)
song_box.pack(side=LEFT,fill=BOTH)
s.pack(side=RIGHT,fill=BOTH)


list2=["previous","current","next"]

#Functions for control buttons

def play():
name=song_box.get(ACTIVE)
a=0
for i in music_file_path:
if name in i:
mixer.music.load(music_file_path[a])
mixer.music.play()
list2[0]=music_file_path[a-1]
list2[1]=music_file_path[a]
list2[2]=music_file_path[a+1]
song_box.select_clear(ACTIVE)
a+=1

def previous():
name=list2[0]
mixer.music.load(name)
mixer.music.play()
a=0
for i in music_file_path:
if name in i:
list2[0]=music_file_path[a-1]
list2[1]=music_file_path[a]
list2[2]=music_file_path[a+1]
song_box.activate(a)
a+=1

def next():
name=list2[2]
mixer.music.load(name)
mixer.music.play()
a=0
for i in music_file_path:
if name in i:
list2[0]=music_file_path[a-1]
list2[1]=music_file_path[a]
list2[2]=music_file_path[a+1]
song_box.activate(a)
a+=1

def quit():
a=askyesno("Quit","Are you sure to quit?")
if a==True:
showinfo("Good bye","Visit us again")
root.destroy()
else:
showinfo("Thanks","Thanks for being with us")


b1=Button(bottom_frame,text="Shuffle",border=5,width=4)
b2=Button(bottom_frame,text="Previous",border=5,width=4, command=previous)
b3=Button(bottom_frame,text="Play",border=5,command=play,width=4)
b4=Button(bottom_frame,text="Next",border=5 ,command=next,width=4)
b5=Button(bottom_frame,text="Quit",border=5,command=quit,width=4)


b1.grid(row=0, column=0)
b2.grid(row=0, column=1)
b3.grid(row=0, column=2)
b4.grid(row=0, column=3)
b5.grid(row=0, column=4)

root.mainloop()
------------------------------------------------------------------------



This is course on Music player with Python using Tkinter and pygame mixer, in this we course we are coding on android app Pydroid3, so if have don't have a Laptop don't worry, we will teach you how to code on android with no charges, free of cost.

On our channel Music Player and Notepad course are going on, absolutely free of cost and we are coding in android, so join the course right now, first time on youtube you will get these two courses which are being done in android using Pydroid3 app.

Pydroid3 app link : https://play.google.com/store/apps/de...
------------------------------------------------------------------------
#programming #coding #programmer
#codeonandroid #pydroid3
#python3 #pythononandroid #coding
#tkinter #pygame #musicplayer #music
#python #developer #javascript #technology #code #coder #computerscience #software #technology #codinglife #softwaredeveloper #programmers #programminglife #pythonprogramming #computer #softwareengineer
#shivamstudio6662 #binarycup
#mohitkhatak #shivam @binarycup

------------------------------------------------------------------------
Coder : Mohit Khatak
Stay connected with us
Contact : +918950097115
Whatsapp: +918950097115
Mail : [email protected]
Website : https://shivam6662.w3spaces.com
Another website : http://shivam6662.epizy.com
© SHIVA+M STUDIO, BINARY CUP