Я написал приложение, которое парсит курсы валют и выводит их на экран, но столкнулся с проблемой. Переменная value не найдена не смотря на "return"
import customtkinter
from tkinter import *
import functools
import requests
from bs4 import BeautifulSoup
app = customtkinter.CTk()
n = 2
after_id = None
menu_open = False
omvar = customtkinter.StringVar(app)
def timeout():
print('timeout called')
omvar.set('')
app.update()
def open(event):
print('open called')
global after_id, menu_open
after_id = app.after(n*1000, timeout)
menu_open = True
def close(value):
print('closed by', value)
global after_id, menu_open
app.after_cancel(str(after_id))
after_id = None
menu_open = False
return value
def get_result():
if value == 'Доллар [USD]':
url = 'https://www.google.com/search?q=%D0%BA%D1%83%D1%80%D1%81+%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80%D0%B0+%D0%BA+%D1%80%D1%83%D0%B1%D0%BB%D1%8E&sxsrf=APwXEddxdL_qEKHbeJ6AXBps3FCVpG4CTg%3A1687966081544&source=hp&ei=gVGcZJnTHa_Bxc8PzIuQuAk&iflsig=AOEireoAAAAAZJxfkbLQgnLIrwQo_Hkfc5JhaefINDgo&oq=%D0%BA%D1%83%D1%80%D1%81+%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80&gs_lcp=Cgdnd3Mtd2l6EAEYATILCAAQgAQQsQMQgwEyCwgAEIAEELEDEIMBMgsIABCABBCxAxCDATILCAAQgAQQsQMQgwEyBQgAEIAEMgsIABCABBCxAxCDATIFCAAQgAQyCwgAEIAEELEDEIMBMgsIABCABBCxAxCDATIFCAAQgAQ6BwgjEOoCECc6BAgjECc6EQguEIAEELEDEIMBEMcBENEDOhEILhCKBRCxAxCDARDHARDRAzoFCC4QgAQ6EQgAEIAEELEDEIMBEAoQARAqOgkIABCABBAKEAE6DwgAEIAEELEDEIMBEAoQAToHCCMQigUQJzoLCAAQigUQsQMQgwE6DAgjEIoFECcQRhD_AToNCAAQgAQQsQMQgwEQCjoHCAAQgAQQCjoECAAQA1C3A1i7K2DXNWgIcAB4AIABcogBpwuSAQQxMy4zmAEAoAEBsAEK&sclient=gws-wiz'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'}
full_page = requests.get(url, headers=headers)
soup = BeautifulSoup(full_page.content, 'html.parser')
convert = soup.findAll("span", {"class": "DFlfde", "data-precision": 2})
label_2['text'] = f'Курс: {str(convert[0].text)}'
print(f'Курс: {str(convert[0].text)}')
elif value == 'Евро [EUR]':
url = 'https://www.google.com/search?q=%D0%BA%D1%83%D1%80%D1%81+%D0%B5%D0%B2%D1%80%D0%BE&sxsrf=AB5stBg5vOKukhzctM2QH0YenHqjjgOeDg%3A1688211261836&source=hp&ei=PQ-gZLnJMIyCi-gPuOWmSA&iflsig=AD69kcEAAAAAZKAdTQntWi8Z_QvMJiocq1CWm1mhmAlR&ved=0ahUKEwj528KEte3_AhUMwQIHHbiyCQkQ4dUDCAk&uact=5&oq=%D0%BA%D1%83%D1%80%D1%81+%D0%B5%D0%B2%D1%80%D0%BE&gs_lcp=Cgdnd3Mtd2l6EAMyCwgAEIAEELEDEIMBMgsIABCABBCxAxCDATILCAAQgAQQsQMQgwEyCwgAEIAEELEDEIMBMgsIABCABBCxAxCDATILCAAQgAQQsQMQgwEyCwgAEIAEELEDEIMBMgsIABCABBCxAxCDATILCAAQgAQQsQMQgwEyCwgAEIAEELEDEIMBOgcIIxDqAhAnOgQIIxAnOgsILhCABBCxAxCDAToRCC4QgAQQsQMQgwEQxwEQ0QM6CAgAEIAEELEDOgUILhCABDoOCC4QgAQQsQMQxwEQ0QM6BQgAEIAEOgsIABCABBAKEAEQKjoJCAAQgAQQChABOgcIIxCKBRAnOgwIIxCKBRAnEEYQggJQ8QNYuCBgpiNoBHAAeACAAb8CiAHyDZIBCDAuMTEuMC4xmAEAoAEBsAEK&sclient=gws-wiz'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'}
full_page = requests.get(url, headers=headers)
soup = BeautifulSoup(full_page.content, 'html.parser')
convert = soup.findAll("span", {"class": "DFlfde", "data-precision": 2})
label_2['text'] = f'Курс: {str(convert[0].text)}'
print(f'Курс: {str(convert[0].text)}')
else:
url = 'https://www.google.com/search?q=%D0%BA%D1%83%D1%80%D1%81+%D0%BC%D0%B0%D0%BD%D0%B0%D1%82%D0%B0+%D0%BA+%D1%80%D1%83%D0%B1%D0%BB%D1%8E&hl=RU&sxsrf=AB5stBiRmyid7H05YJLQbdYdP7ai8--cPQ%3A1688231673617&source=hp&ei=-V6gZKL5ItX5rgT7q6wI&iflsig=AD69kcEAAAAAZKBtCVobgr5Pyd0pf6X3lIIVew5xY8Vb&oq=%D0%9A%D1%83%D1%80%D1%81+%D0%BC%D0%B0%D0%BD%D0%B0%D1%82%D0%B0&gs_lcp=Cgdnd3Mtd2l6EAEYADIKCAAQgAQQRhCCAjILCAAQgAQQsQMQgwEyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDoECCMQJzoLCC4QgAQQsQMQgwE6CAgAEIAEELEDOgcIIxDqAhAnOgcIIxCKBRAnOgsIABCKBRCxAxCDAVAAWOQpYI0xaAFwAHgAgAFeiAHtB5IBAjEymAEAoAEBsAEK&sclient=gws-wiz'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'}
full_page = requests.get(url, headers=headers)
soup = BeautifulSoup(full_page.content, 'html.parser')
convert = soup.findAll("span", {"class": "DFlfde", "data-precision": 2})
label_2['text'] = f'Курс: {str(convert[0].text)}'
print(f'Курс: {str(convert[0].text)}')
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
app.geometry("600x400")
app.title("Курсы валют")
app.resizable(width=False, height=False)
frame_1 = customtkinter.CTkFrame(master=app)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=customtkinter.LEFT, text="Курсы валют", font=('Arial', 50))
label_1.pack(pady=10, padx=10)
optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, values=["Доллар [USD]", "Евро [EUR]", "Манат [AZN]"], command=close)
optionmenu_1.bind('<Button-1>', open)
optionmenu_1.pack(pady=10, padx=10)
optionmenu_1.set("Валюта")
label_2 = Label(master=frame_1, bg='#1f6aa5', text='Цена [RUB]', fg='white', width=15, height=1, font='Arial')
label_2.pack()
button_1 = customtkinter.CTkButton(master=frame_1, text="Узнать", command=functools.partial(get_result))
button_1.pack(pady=10, padx=10)
app.mainloop()
Помогите решить проблему
P.S Да, знаю, много повторяющегося кода, но я написал это за час, поэтому можно закрыть на это глаза