from tkinter import *
from tkinter import filedialog
import pygame.mixer as mixer
import os
root=Tk()
mixer.init()
root.title("Lista de Música")
root.geometry('700x350')
root.configure(background='#A1DFD1')
root.resizable(False, False)
def load(listbox):
os.chdir(filedialog.askdirectory(title='Open a songs directory'))
tracks = os.listdir()
for track in tracks:
listbox.insert(END, track)
def stop(status: StringVar):
mixer.music.stop()
status.set("Song STOPPED")
def pause(status: StringVar):
mixer.music.pause()
status.set("Song PAUSED")
def tirarpause(status: StringVar):
mixer.music.unpause()
status.set("Song UNPAUSED")
def play(song_name: StringVar, songs_list: Listbox, status: StringVar):
song_name.set(songs_list.get(ACTIVE))
mixer.music.load(songs_list.get(ACTIVE))
mixer.music.play()
status.set("Song PLAYING")
# Frames
musica_frame = Frame( bg='#709C92')
musica_frame.place(relx=0.05,rely=0.05,relwidth=0.5,relheight=0.5)
butao_frame = Frame( bg='#709C92')
butao_frame.place(relx=0.05,rely=0.6,relwidth=0.5,relheight=0.35)
lista_frame = Frame( bg='RoyalBlue')
lista_frame.place(relx=0.6,rely=0.05,relwidth=0.35,relheight=0.9)
# Variaveis
musica_corrente = StringVar(root, value='<Not selected>')
estado = StringVar(root, value='<Not Available>')
# PlayList
playlist = Listbox(lista_frame, font=('Helvetica', 11), selectbackground='Gold')
scroll_bar = Scrollbar(lista_frame, orient=VERTICAL)
scroll_bar.place(relx=0.83,rely=0.05,relheight=0.9)
playlist.config(yscrollcommand=scroll_bar.set)
scroll_bar.config(command=playlist.yview)
playlist.place(relx=0.1,rely=0.05,relwidth=0.75,relheight=0.9)
# Primeiro Frame
texto=Label(musica_frame, text='CURRENTLY PLAYING:', bg='LightBlue',
font=('Times', 10, 'bold'))
texto.place(relx=0.2,rely=0.35)
song_lbl = Label(musica_frame, textvariable=musica_corrente, bg='Goldenrod',
font=("Times", 12))
song_lbl.place(relx=0.25,rely=0.5)
# Butões
# Colocar músicas
load_btn = Button(butao_frame, text='Load Directory', bg='green',fg='white',
font=("Arial",9,'bold'),command=lambda: load(playlist))
load_btn.place(relx=0.2,rely=0.7,relwidth=0.6,relheight=0.2)
# Play
play_btn = Button(butao_frame, text='Play', bg='#034005',fg='white',
font=("Georgia", 13),
command=lambda: play(musica_corrente,playlist,estado))
play_btn.place(relx=0.1,rely=0.15,relwidth=0.15,relheight=0.4)
# Stop
stop_btn = Button(butao_frame, text='Stop', bg='red',fg='white',font=("Georgia", 13),
command=lambda: stop(estado))
stop_btn.place(relx=0.3,rely=0.15,relwidth=0.15,relheight=0.4)
pause_btn = Button(butao_frame, text='Pause', bg='Black',fg='white',
font=("Georgia", 13), width=7,
command=lambda: pause(estado))
# Pausa
pause_btn.place(relx=0.5,rely=0.15,relwidth=0.15,relheight=0.4)
tirara_pause_btn = Button(butao_frame, text='Tirar\nPausa', bg='#B7B7B7',fg='white',
font=("Georgia", 13), width=7,
command=lambda: tirarpause(estado))
# Tirar
tirara_pause_btn.place(relx=0.7,rely=0.15,relwidth=0.15,relheight=0.4)
root.update()
root.mainloop()
Comentários
Enviar um comentário