0

I'm making a music player using pygame and tkinter, I'm done with the UI, I just don't know how I would import the songs and make them play/pause/skip based on the buttons I made. I haven't tried anything because I don't know how I would go about it, if anyone knows and can help me out it'd be great! Thanks!

from tkinter import *
import tkinter.font as font
from tkinter import filedialog 
from pygame import mixer
## importing required tkinter libraries

def Play():
    print("Play")

root = Tk()
root.title="MP3 Music Player"
mixer.init()


##listbox where your songs will be loaded into
songs_list = Listbox(root,selectmode=SINGLE,bg="black",fg="white",font=('arial',15),height=12,width=47,selectbackground="gray",selectforeground="black")
songs_list.grid(columnspan=9)

#set new default font
default_font = font.Font(family="Helvetica")

##play button
play_button = Button(root,text="Play",width=7,command=Play) ##initialise/create each button with its specified properties
play_button['font'] = default_font ## change font of each button
play_button.grid(row=1,column=0) ## sets position of where button is to be located for each button

##pause button
pause_button = Button(root, text="Pause",width = 7, command=Play)
pause_button['font'] = default_font
pause_button.grid(row=1,column=1)

## stop button
stop_button = Button(root,text="Stop",width=7,command=Play)
stop_button['font'] = default_font
stop_button.grid(row=1,column=2)

## resume button
resume_button = Button(root,text="Resume",width=7,command=Play)
resume_button['font'] = default_font
resume_button.grid(row=1,column=3)

##previous button
previous_button = Button(root,text="Prev",width=7,command=Play)
previous_button['font'] = default_font
previous_button.grid(row=1,column=4)


## next button
next_button = Button(root,text="Next",width=7,command=Play)
next_button['font'] = default_font
next_button.grid(row=1,column=5)


##create menu option
menu = Menu(root)
root.config(menu=menu)
add_song_menu = Menu(menu)
menu.add_cascade(label="Menu",menu=add_song_menu)
add_song_menu.add_command(label="Add songs",command=Play)
add_song_menu.add_command(label="Delete song",command=Play)


Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • You need file paths to play songs. You can use the os module to create the list: [os.listdir/os.scandir/os.walk](https://docs.python.org/3/library/os.html#files-and-directories). – 8349697 Dec 11 '22 at 19:52
  • See also: https://docs.python.org/3/library/dialog.html#module-tkinter.filedialog – 8349697 Dec 11 '22 at 19:56

0 Answers0