|
| 1 | +import pygame |
| 2 | +from pygame import mixer |
| 3 | +from tkinter import * |
| 4 | +import os |
| 5 | + |
| 6 | +def playsong(): |
| 7 | + currentsong=playlist.get(ACTIVE) |
| 8 | + print(currentsong) |
| 9 | + mixer.music.load(currentsong) |
| 10 | + songstatus.set("Playing") |
| 11 | + mixer.music.play() |
| 12 | + |
| 13 | +def pausesong(): |
| 14 | + songstatus.set("Paused") |
| 15 | + mixer.music.pause() |
| 16 | + |
| 17 | +def stopsong(): |
| 18 | + songstatus.set("Stopped") |
| 19 | + mixer.music.stop() |
| 20 | + |
| 21 | +def resumesong(): |
| 22 | + songstatus.set("Resuming") |
| 23 | + mixer.music.unpause() |
| 24 | + |
| 25 | + |
| 26 | +root=Tk() |
| 27 | +root.title('Buddy Music player') |
| 28 | + |
| 29 | +mixer.init() |
| 30 | +songstatus=StringVar() |
| 31 | +songstatus.set("choosing") |
| 32 | + |
| 33 | +#playlist--------------- |
| 34 | + |
| 35 | +os.chdir(r'D:\MyPlayList') |
| 36 | + |
| 37 | +playlist=Listbox(root,selectmode=SINGLE,bg="DodgerBlue2",fg="white",font=('arial',15),width=40) |
| 38 | +playlist.grid(columnspan=5) |
| 39 | +songs=os.listdir() |
| 40 | +for s in songs: |
| 41 | + playlist.insert(END,s) |
| 42 | + |
| 43 | +playbtn=Button(root,text="play",command=playsong) |
| 44 | +playbtn.config(font=('arial',20),bg="DodgerBlue2",fg="white",padx=7,pady=7) |
| 45 | +playbtn.grid(row=1,column=0) |
| 46 | + |
| 47 | +pausebtn=Button(root,text="Pause",command=pausesong) |
| 48 | +pausebtn.config(font=('arial',20),bg="DodgerBlue2",fg="white",padx=7,pady=7) |
| 49 | +pausebtn.grid(row=1,column=1) |
| 50 | + |
| 51 | +stopbtn=Button(root,text="Stop",command=stopsong) |
| 52 | +stopbtn.config(font=('arial',20),bg="DodgerBlue2",fg="white",padx=7,pady=7) |
| 53 | +stopbtn.grid(row=1,column=2) |
| 54 | + |
| 55 | +Resumebtn=Button(root,text="Resume",command=resumesong) |
| 56 | +Resumebtn.config(font=('arial',20),bg="DodgerBlue2",fg="white",padx=7,pady=7) |
| 57 | +Resumebtn.grid(row=1,column=3) |
| 58 | + |
| 59 | + |
| 60 | +mainloop() |
0 commit comments