Reputation: 259
I'm working on Music player and when I play a new song I always call songInfoDisplay function. As you can see on the picture (link below) songs information are not displayed properly. Is there a way how to fix it? Thank you for your time and answers.
master = Tk()
def playSong():
song = lb.get(ACTIVE)
pathToSong = (path + "\\" + song)
mixer.music.load(pathToSong)
mixer.music.play()
audio = MP3(pathToSong)
songLength = int(audio.info.length)
songInfo=mutagen.File(pathToSong, easy=True)
songInfoDisplay()
def songInfoDisplay():
songLabel=Label(master, text=songInfo["title"])
artistLabel=Label(master, text=songInfo["artist"])
albumLabel=Label(master, text=songInfo["album"])
artistLabel.grid(row=5, column=3, stick=E)
songLabel.grid(row=6, column=3, stick=E)
albumLabel.grid(row=7, column=3, stick=E)
Upvotes: 0
Views: 47
Reputation: 46669
You should create those labels once when program starts, then update their text when a song is selected. Below is a modified example based on your code:
master = Tk()
# create the required labels
songLabel=Label(master)
artistLabel=Label(master)
albumLabel=Label(master)
artistLabel.grid(row=5, column=3, stick=E)
songLabel.grid(row=6, column=3, stick=E)
albumLabel.grid(row=7, column=3, stick=E)
def playSong():
song = lb.get(ACTIVE)
pathToSong = (path + "\\" + song)
mixer.music.load(pathToSong)
mixer.music.play()
audio = MP3(pathToSong)
songLength = int(audio.info.length)
songInfo=mutagen.File(pathToSong, easy=True)
songInfoDisplay(songInfo) # pass songInfo to songInfoDisplay()
def songInfoDisplay(songInfo):
# show the song information
songLabel.config(text=songInfo["title"][0])
artistLabel.config(text=songInfo["artist"][0])
albumLabel.config(text=songInfo["album"][0])
Upvotes: 1