'I cant seem to create a window that updates what im listening to on Spotify

Ive been trying to make a app that will grab what the user is listening to on Spotify and the next song that will play so they can skip songs

So far i just want to grab what they are listening to which i can do, but i cant seem to be able to show it up in a window with tkinter

Anyone got links that will help me, or can just help?

Thanks so much in advance

import requests
from pprint import pprint
from tkinter import * 
from tkinter.ttk import *
import time 

SPOTIFY_GET_CURRENT_TRACK_URL = 'https://api.spotify.com/v1/me/player/currently-playing'
ACCESS_TOKEN = 'BQB8Lx8s3NidrRVZB0CTG04EGYn-tLeD5gvTa-uk2sjuADzy3vJp5LvUrdcSRCGtaCD7GKBJXBmSFIprZQ_U5_YcvemHZ_ROlfVjwWbM2RH7wZ80lR-YX3C4oG12CEqURcet_djqf3d-ggwv-M-fms'



def get_current_track(ACCESS_TOKEN):
    response = requests.get(
        SPOTIFY_GET_CURRENT_TRACK_URL,
        headers={
            "Authorization": f"Bearer {ACCESS_TOKEN}"
        }
    )
    json_resp = response.json()

    track_id = json_resp['item']['id']
    track_name = json_resp['item']['name']
    artists = [artist for artist in json_resp['item']['artists']]

    link = json_resp['item']['external_urls']['spotify']

    artist_names = ', '.join([artist['name'] for artist in artists])
    progress_time = json_resp['progress_ms']
    duration_time = json_resp['item']['duration_ms']
    current_song_time = json_resp['progress_ms'] / json_resp['item']['duration_ms'] * 100

    current_track_info = {
        "id": track_id,
        "track_name": track_name,
        "artists": artist_names,
        "link": link,
        "progress": progress_time,
        "duration": duration_time,
        "song_time": current_song_time
    }
    return current_track_info


def CreateWin():
    # creating tkinter window
    current_track_info = get_current_track(ACCESS_TOKEN)
    root = Tk()
    root.title('Current Song')
    root.geometry('500x500')
    root.config(bg='#84BF04')
    
    Wrds = '''
    "Image here" , 
    "Track" {name} ,
    "Artists" {Art} 
    '''

    message = Wrds.format(name = current_track_info['track_name'], Art = current_track_info['artists'])

    label = StringVar()
    label.set(message)

    L_label = Label(root, textvariable=label)
    L_label.pack()

    Button(root, text = 'Refresh', command = get_current_track(ACCESS_TOKEN) ).pack(pady = 10)
  
def Main():
    current_track_info = get_current_track(ACCESS_TOKEN)
    current_track_id = None
    CreateWin()
    while True:
        if current_track_info['id'] != current_track_id:
            pprint(
                current_track_info,
                indent=4,
            )
            current_track_id = current_track_info['id']


if __name__ == '__main__':
    Main()
    
    
    ```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source