I have created a tkinter GUI.
I have bound a function def scrape to a button.
When I press the button, selenium will get data from different elements and stores them in different lists.
In my GUI I want to have an OptionMenu for each of the lists.
The problem is, the list is created after I press the button.
When I want to add the OptionMenuto the GUI and load a list as values it gets me an error there is no variable "list". This is because when app.mainloop() starts there is not list created yet.
This s my scraping code:
def scrape():
li_leagues = []
print('Getting leagues...\n')
#click the dropdown menue to open the folder
league_dropdown_menu = driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[1]/div[1]/div[7]/div')
league_dropdown_menu.click()
time.sleep(1)
# scrape all text
scrape_leagues = driver.find_elements_by_xpath("//li[@class='with-icon' and contains(text(), '')]")
for league in scrape_leagues:
export_league = league.text
export_league = str(export_league)
export_league = export_league.replace(',', '')
li_leagues.append(export_league)
This is what I tried for the OptionMenu:
str_quality = StringVar()
str_quality.set(li_quality[0])
#Dropdown
d_quality = OptionMenu(app, str_quality, *li_quality)
How can i make it working that I can add the OptionMenu to my GUI?
EDIT:
I added the name of the list as an empty list li_quality = [] to the code before app.mainloop() gets called.
The GUI is loading now with the OptionMenu. But it doesnt get updated after I scraped my data.