mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-12-18 00:00:17 +00:00
commit
37ce6cfa16
13
scripts/Music Player/README.md
Normal file
13
scripts/Music Player/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Music Player GUI
|
||||
|
||||
![Screenshot (465)](https://user-images.githubusercontent.com/48403800/195563802-fdc224c3-8325-4e1b-b768-2d85e44a3666.png)
|
||||
|
||||
This is a GUI framework where two GUI libraries are used:
|
||||
|
||||
- Pygame
|
||||
- Tkinter
|
||||
|
||||
It has functions such as play, stop, pause and resume in order to control the music player.
|
||||
|
||||
To create a music player with Python, we will be using the **Pygame** sound component and _askdirectory()_ method of Tkinter
|
||||
|
45
scripts/Music Player/music-player.py
Normal file
45
scripts/Music Player/music-player.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import pygame
|
||||
import tkinter as tkr
|
||||
from tkinter.filedialog import askdirectory
|
||||
import os
|
||||
|
||||
music_player = tkr.Tk()
|
||||
music_player.title("My Music Player")
|
||||
music_player.geometry("450x350")
|
||||
directory = askdirectory()
|
||||
os.chdir(directory)
|
||||
song_list = os.listdir()
|
||||
|
||||
play_list = tkr.Listbox(music_player, font="Helvetica 12 bold", bg='yellow', selectmode=tkr.SINGLE)
|
||||
for item in song_list:
|
||||
pos = 0
|
||||
play_list.insert(pos, item)
|
||||
pos += 1
|
||||
pygame.init()
|
||||
pygame.mixer.init()
|
||||
|
||||
def play():
|
||||
pygame.mixer.music.load(play_list.get(tkr.ACTIVE))
|
||||
var.set(play_list.get(tkr.ACTIVE))
|
||||
pygame.mixer.music.play()
|
||||
def stop():
|
||||
pygame.mixer.music.stop()
|
||||
def pause():
|
||||
pygame.mixer.music.pause()
|
||||
def unpause():
|
||||
pygame.mixer.music.unpause()
|
||||
Button1 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="PLAY", command=play, bg="blue", fg="white")
|
||||
Button2 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="STOP", command=stop, bg="red", fg="white")
|
||||
Button3 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="PAUSE", command=pause, bg="purple", fg="white")
|
||||
Button4 = tkr.Button(music_player, width=5, height=3, font="Helvetica 12 bold", text="UNPAUSE", command=unpause, bg="orange", fg="white")
|
||||
|
||||
var = tkr.StringVar()
|
||||
song_title = tkr.Label(music_player, font="Helvetica 12 bold", textvariable=var)
|
||||
|
||||
song_title.pack()
|
||||
Button1.pack(fill="x")
|
||||
Button2.pack(fill="x")
|
||||
Button3.pack(fill="x")
|
||||
Button4.pack(fill="x")
|
||||
play_list.pack(fill="both", expand="yes")
|
||||
music_player.mainloop()
|
2
scripts/Music Player/requirements.txt
Normal file
2
scripts/Music Player/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
pygame
|
||||
tkinter
|
Loading…
Reference in New Issue
Block a user