Spaces:
No application file
No application file
README.md
Browse files- README. md +79 -0
README. md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tkinter as tk
|
| 2 |
+
from tkinter import filedialog
|
| 3 |
+
from pygame import mixer
|
| 4 |
+
|
| 5 |
+
class JukeboxMusic:
|
| 6 |
+
def __init__(self, root):
|
| 7 |
+
self.root = root
|
| 8 |
+
self.root.title("Jukebox Music")
|
| 9 |
+
self.root.geometry("300x200")
|
| 10 |
+
|
| 11 |
+
# Initialize Pygame mixer
|
| 12 |
+
mixer.init()
|
| 13 |
+
|
| 14 |
+
# Create playlist frame
|
| 15 |
+
self.playlist_frame = tk.Frame(self.root)
|
| 16 |
+
self.playlist_frame.pack(fill="both", expand=True)
|
| 17 |
+
|
| 18 |
+
# Create playlist listbox
|
| 19 |
+
self.playlist = tk.Listbox(self.playlist_frame)
|
| 20 |
+
self.playlist.pack(fill="both", expand=True)
|
| 21 |
+
|
| 22 |
+
# Create buttons frame
|
| 23 |
+
self.buttons_frame = tk.Frame(self.root)
|
| 24 |
+
self.buttons_frame.pack(fill="x")
|
| 25 |
+
|
| 26 |
+
# Create play button
|
| 27 |
+
self.play_button = tk.Button(self.buttons_frame, text="Play", command=self.play_music)
|
| 28 |
+
self.play_button.pack(side="left")
|
| 29 |
+
|
| 30 |
+
# Create pause button
|
| 31 |
+
self.pause_button = tk.Button(self.buttons_frame, text="Pause", command=self.pause_music)
|
| 32 |
+
self.pause_button.pack(side="left")
|
| 33 |
+
|
| 34 |
+
# Create stop button
|
| 35 |
+
self.stop_button = tk.Button(self.buttons_frame, text="Stop", command=self.stop_music)
|
| 36 |
+
self.stop_button.pack(side="left")
|
| 37 |
+
|
| 38 |
+
# Create add song button
|
| 39 |
+
self.add_song_button = tk.Button(self.buttons_frame, text="Add Song", command=self.add_song)
|
| 40 |
+
self.add_song_button.pack(side="left")
|
| 41 |
+
|
| 42 |
+
# Create remove song button
|
| 43 |
+
self.remove_song_button = tk.Button(self.buttons_frame, text="Remove Song", command=self.remove_song)
|
| 44 |
+
self.remove_song_button.pack(side="left")
|
| 45 |
+
|
| 46 |
+
def play_music(self):
|
| 47 |
+
# Get selected song from playlist
|
| 48 |
+
selected_song = self.playlist.get(tk.ACTIVE)
|
| 49 |
+
if selected_song:
|
| 50 |
+
# Play selected song
|
| 51 |
+
mixer.music.load(selected_song)
|
| 52 |
+
mixer.music.play()
|
| 53 |
+
|
| 54 |
+
def pause_music(self):
|
| 55 |
+
# Pause music
|
| 56 |
+
mixer.music.pause()
|
| 57 |
+
|
| 58 |
+
def stop_music(self):
|
| 59 |
+
# Stop music
|
| 60 |
+
mixer.music.stop()
|
| 61 |
+
|
| 62 |
+
def add_song(self):
|
| 63 |
+
# Open file dialog to select song
|
| 64 |
+
song_path = filedialog.askopenfilename(filetypes=[("Audio Files", ".mp3.wav")])
|
| 65 |
+
if song_path:
|
| 66 |
+
# Add song to playlist
|
| 67 |
+
self.playlist.insert(tk.END, song_path)
|
| 68 |
+
|
| 69 |
+
def remove_song(self):
|
| 70 |
+
# Get selected song from playlist
|
| 71 |
+
selected_song = self.playlist.get(tk.ACTIVE)
|
| 72 |
+
if selected_song:
|
| 73 |
+
# Remove song from playlist
|
| 74 |
+
self.playlist.delete(tk.ACTIVE)
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
root = tk.Tk()
|
| 78 |
+
app = JukeboxMusic(root)
|
| 79 |
+
root.mainloop()
|