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