Skip to content

Commit 37ce6cf

Browse files
authored
Merge pull request metafy-social#393 from srishti011/master
Music Player GUI
2 parents 12ff448 + 63c81b7 commit 37ce6cf

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

scripts/Music Player/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Music Player GUI
2+
3+
![Screenshot (465)](https://user-images.githubusercontent.com/48403800/195563802-fdc224c3-8325-4e1b-b768-2d85e44a3666.png)
4+
5+
This is a GUI framework where two GUI libraries are used:
6+
7+
- Pygame
8+
- Tkinter
9+
10+
It has functions such as play, stop, pause and resume in order to control the music player.
11+
12+
To create a music player with Python, we will be using the **Pygame** sound component and _askdirectory()_ method of Tkinter
13+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import pygame
2+
import tkinter as tkr
3+
from tkinter.filedialog import askdirectory
4+
import os
5+
6+
music_player = tkr.Tk()
7+
music_player.title("My Music Player")
8+
music_player.geometry("450x350")
9+
directory = askdirectory()
10+
os.chdir(directory)
11+
song_list = os.listdir()
12+
13+
play_list = tkr.Listbox(music_player, font="Helvetica 12 bold", bg='yellow', selectmode=tkr.SINGLE)
14+
for item in song_list:
15+
pos = 0
16+
play_list.insert(pos, item)
17+
pos += 1
18+
pygame.init()
19+
pygame.mixer.init()
20+
21+
def play():
22+
pygame.mixer.music.load(play_list.get(tkr.ACTIVE))
23+
var.set(play_list.get(tkr.ACTIVE))
24+
pygame.mixer.music.play()
25+
def stop():
26+
pygame.mixer.music.stop()
27+
def pause():
28+
pygame.mixer.music.pause()
29+
def unpause():
30+
pygame.mixer.music.unpause()
31+
Button1 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="PLAY", command=play, bg="blue", fg="white")
32+
Button2 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="STOP", command=stop, bg="red", fg="white")
33+
Button3 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="PAUSE", command=pause, bg="purple", fg="white")
34+
Button4 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="UNPAUSE", command=unpause, bg="orange", fg="white")
35+
36+
var = tkr.StringVar()
37+
song_title = tkr.Label(music_player, font="Helvetica 12 bold", textvariable=var)
38+
39+
song_title.pack()
40+
Button1.pack(fill="x")
41+
Button2.pack(fill="x")
42+
Button3.pack(fill="x")
43+
Button4.pack(fill="x")
44+
play_list.pack(fill="both", expand="yes")
45+
music_player.mainloop()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pygame
2+
tkinter

0 commit comments

Comments
 (0)