I'm trying to get the image from the song album to display in the window with the song title and artist but it just doesn't do anything. I've tried replacing the "imageLabel" with
"imageLabel = tkinter.Label(window,image=tkinter.PhotoImage(file="CurrentSong.jpg"))" but it still doesn't work.
import requests
import time
import tkinter
token = ''
endpoint = "https://api.spotify.com/v1/me/player/currently-playing"
spotifyHeaders = {'Authorization':'Bearer ' + token}
requestAmount = 1
window = tkinter.Tk(className="|CurrentSong Spotify Song|")
window.geometry('400x400')
canvas = tkinter.Canvas(window,height=1000,width=1000)
canvas.pack()
songLabel = tkinter.Label(window,bg='grey')
songLabel.pack()
def GrabSpotifyCurSong(curSongJson):
return curSongJson['item']['name']
def GrabSpotifyCurArtist(curSongJson):
return curSongJson['item']['artists'][0]['name']
def GrabCurrentSongImage(curSongJson):
return curSongJson['item']['album']['images'][0]['url']
def displaySongs():
while True:
try:
curSong = requests.get(endpoint, headers=spotifyHeaders)
curSongJson = curSong.json()
break
except:
print("Please start listening to a song")
time.sleep(2)
with open('CurrentSong.png','wb+') as SongImage:
response = requests.get(GrabCurrentSongImage(curSongJson))
SongImage.write(response.content)
currentSong = GrabSpotifyCurSong(curSongJson)
currentArtist = GrabSpotifyCurArtist(curSongJson)
img = tkinter.PhotoImage(file="CurrentSong.png")
imageLabel = tkinter.Label(window,image=img)
# songLabel['text'] = f'{currentArtist} - {currentSong}'
# songLabel.place(height=400,width=400)
print(f'{currentArtist} - {currentSong}')
window.after(2500,displaySongs)
displaySongs()
window.mainloop()