I'm trying to build an application to get a songs from a user's spotify playlists, where users can enter their username and have the program make a request to the Spotipy API. But, I'm running into an issue where the program wont wait for the user to submit the text before setting up the next widget containing the data received from the request.
#get token
token = req.get_token()
#create window
top = App()
#entry field for user submission
user_Id = ctk.StringVar()
entry = ctk.CTkEntry(top,textvariable = user_Id, width = 200)
entry.pack(padx=20, pady=10)
#get user button, have them pass their user ID
submitButton = ctk.CTkButton(top,text="Enter",command=top.quit)
submitButton.pack()
top.mainloop()
userID = user_Id.get()
'''
send query to spotipy api.
Returns an array of dictionaries
containing playlist info
'''
result = req.search_for_user_playlists(token, userID)
#play array will hold every found playlist
playDict = {}
#fill playlist dictionary
for item in result:
playDict.update({item["name"] : item["id"]})
songsList = []
#dropdown menu containing playlist names
drop = ctk.CTkOptionMenu(master = top,values = list(playDict.keys()), dynamic_resizing=True)
drop.pack(pady = 10)
I did a little work around where I have the window quit, and then call mainloop, and continue to add in widgets after that, but from what I've seen this is bad practice. I tried fixing it by having it run the request function as the button command, but it caused subsequent functions to fail, as the widgets where being packed before the right variables could be set. I also tried the wait_variable method, by having a boolean value get set on the submitButton press (as a command), but it didn't work. I'd like to have the program setup in a way so that each widget only gets setup and packed after the previous field has had it's relevant information submitted.