Jukeboxmusic / README. md
SethyYann98's picture
README.md
432cf47 verified
raw
history blame
2.59 kB
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()