I'm a complete beginner in Python and currently making a GUI with Tkinter that can play mp3 files. just for practice.
I'm using a Mac, and the rainbow wheel that appears when a program lags shows up when I press the play button I made. And it doesn't let me press any buttons while the mp3 file is playing.
Can anybody help me figure this out please?
from pydub import AudioSegment
from pydub.playback import play
from tkinter import *
class MP3:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.go_back_button = Button(frame, text = '<<')
self.go_back_button.grid(row = 0 , column = 0)
self.play_button = Button(frame, text = '|>', command = self.play_song)
self.play_button.grid(row = 0 , column = 1)
self.pause_button = Button(frame, text = '||', command = self.pause_song)
self.pause_button.grid(row = 0 , column = 2)
self.go_forward_button = Button(frame, text = '>>')
self.go_forward_button.grid(row = 0 , column = 3)
self.shuffle_button = Button(frame, text = 'SHUFFLE')
self.shuffle_button.grid(row = 0 , column = 4)
self.is_paused = False
self.song_list = ['songs.mp3']
self.i = 0
def play_song(self):
while self.is_paused is False:
song = AudioSegment.from_mp3("/Users/bang/Desktop/music/{}".format(self.song_list[self.i]))
play(song)
def pause_song(self):
self.is_paused = True
root = Tk()
myMp3 = MP3(root)
root.mainloop()