I'm Difficult to make the program choose music and play selected music
from tkinter import *
from tkinter import messagebox
from tkinter.filedialog import askopenfilename
from pygame import *
from pygame import mixer
jan = Tk()
jan.title("JANELAA")
jan.geometry('400x400')
class Sistema:
def __init__(self, box):
self.frame = Frame(box)
self.frame.pack()
self.menu = Menu(box)
self.menuFile = Menu(self.menu)
self.menuFile.add_command(label="Notepad" , command=self.note)
self.menu.add_cascade(label="File", menu=self.menuFile)
self.menuMusc = Menu(self.menu)
self.menuMusc.add_command(label="|Play|", command=self.play)
self.menuMusc.add_command(label="|Pause|", command=self.pause)
self.menuMusc.add_command(label="|Retomar|", command=self.unpause)
self.menuMusc.add_command(label="|Parar|", command=self.stop)
self.menuMusc.add_command(label="|Escolha|", command=self.escolher)
self.menu.add_cascade(label="Musicas" , menu=self.menuMusc)
self.menuOption = Menu(self.menu)
self.menu.add_cascade(label="Options" , menu=self.menuOption)
box.config(menu=self.menu)
def note(self):
textField = Text(jan, width=300)
textField.pack(side=LEFT, expand=True, fill='both')
scrollBar = Scrollbar(jan)
scrollBar.pack(side=RIGHT, fill=Y)
scrollBar.config(command=textField.yview)
textField.config(yscrollcommand=scrollBar.set)
def salvar():
name = filedialog.asksaveasfile(mode='w', defaultextension=".txt")
t =textField.get(0.0, END) # Pega o texto do textField
name.write(t.rstrip()) # Escreve o texto no arquivo criado
bt = Button(jan, text="Salvar", command=salvar)
bt.place(x=360 , y=0)
def play(self):
mixer.init()
mixer.music.load('coldb.mp3')
mixer.music.play(1 , 1)
musica_tocando = True
while mixer.music.get_busy():
time.Clock().tick(10)
for event in event.get() :
if event.type == MOUSEBUTTONDOWN:
if musica_tocando:
mixer.music.pause()
musica_tocando = False
else:
mixer.music.unpause()
musica_tocando = True
def pause(self):
mixer.music.pause()
def unpause(self):
mixer.music.unpause()
def stop(self):
mixer.music.stop()
def escolher (self):
selecionar = askopenfilename(initialdir="C:/Users/%user%/desktop",
filetypes =(("Arquivo de audio", "*.mp3"),("All Files","*.*")),
title = "Selecione as musicas"
)
if selecionar == '': # Se tiver '' ele não faz nada ( pass )
pass
else:
mixer.music.load.append(selecionar)
jan.wm_resizable(0, 0)
Sistema(jan)
jan.mainloop()