I am new to Python and I want to present a dropdownlist i.e. Netflix, Now TV, Amazon Prime etc using the optionmenu provided by TKinter. The dropdownlist should display the text values listed above but each item will have a unique identifier which I don't want to display in the dropdownlist. The data I get back from the API is as follows:
[{'id': 1, 'name': 'Netflix'}, {'id': 2, 'name': 'Now TV'}, {'id': 3, 'name': 'Amazon'}]
and I want a list displayed like:
Netflix
Now TV
Amazon
When an item is selected I will want to select the id from the item selected so I can make an API call and get the full information.
In effect each item in the list will have the unique identifier but not displayed in the optionmenu.
What I have displayed in the optionmenu is: "{'id': 1, 'name': 'Netflix'} when I want just the name value "Netflix"
this is an extract of the code that populates the optionmenu and handles the selection.
accounts = accountsAPI.getAccounts()
def change(*args):
selectedItem = var.get()
print(selectedItem)
if selectedItem in accounts:
print(accounts.get())
var = StringVar(root)
var.trace("w",change)
dropDownMenuAccounts = OptionMenu(root,var,*accounts)
dropDownMenuAccounts.grid(row=0,column=1, padx=10,pady=10)
Can anyone guide me in the right direction on how I can accomplish this.