Вообщем хочу создать прогу, чтобы узнать погодку, но при нажатии узнать выводится ошибка
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "pogodaGUI.py", line 59, in <lambda>
return lambda : callback(id, tex)
File "pogodaGUI.py", line 62, in callback
s = 'Утром: ' + pogoda1 + ' ' + pogoda2 + ' Днём: ' + pogoda3 + ' ' + pogoda4
NameError: name 'pogoda1' is not defined
А вот сам код
from tkinter import *
from tkinter.ttk import *
import requests, bs4
import sys
top = Tk()
#root = Tk()
###
#text = Text(width=25, height=5, bg="darkgreen", fg='white', wrap=WORD)
#text.pack()
#text = print ('Ага')
#text.pack ()
#root.mainloop()
# s = requests.get('https://sinoptik.com.ru/погода-)
# b = bs4.BeautifulSoup(s.text, "html.parser")
# p3=b.select('.temperature .p3')
# pogoda1=p3[0].getText()
# p4=b.select('.temperature .p4')
# pogoda2=p4[0].getText()
# p5=b.select('.temperature .p5')
# pogoda3=p5[0].getText()
# p6=b.select('.temperature .p6')
# pogoda4=p6[0].getText()
v = StringVar()
e = Entry(top, textvariable=v)
e.pack()
def get_value():
print(v.get())
def clean_value():
v.set("")
b1 = Button(top, text="Ваш город", width=10, command=get_value)
b2 = Button(top, text="очистить", width=10, command=clean_value)
b1.pack()
b2.pack()
def pogoda():
global pogoda1
global pogoda2
global pogoda3
global pogoda4
s = requests.get('https://sinoptik.com.ru/погода-' + v)
b = bs4.BeautifulSoup(s.text, "html.parser")
p3=b.select('.temperature .p3')
pogoda1=p3[0].getText()
p4=b.select('.temperature .p4')
pogoda2=p4[0].getText()
p5=b.select('.temperature .p5')
pogoda3=p5[0].getText()
p6=b.select('.temperature .p6')
pogoda4=p6[0].getText()
def cbc(id, tex):
return lambda : callback(id, tex)
def callback(id, tex):
s = 'Утром: ' + pogoda1 + ' ' + pogoda2 + ' Днём: ' + pogoda3 + ' ' + pogoda4
tex.insert(END, s)
tex.see(END) # Scroll if necessary
# top = Tk()
tex = Text(master=top)
tex.pack(side=RIGHT)
bop = Frame()
bop.pack(side=LEFT)
for k in range(1):
tv = 'узнать {}'.format(k)
b = Button(bop, text=tv, command=cbc(k, tex))
b.pack()
Button(bop, text='Свалить', command=top.destroy).pack()
###
# v = StringVar()
# e = Entry(top, textvariable=v)
# e.pack()
# def get_value():
# print(v.get())
# def clean_value():
# v.set("")
# b1 = Button(top, text="Ваш город", width=10, command=get_value)
# b2 = Button(top, text="очистить", width=10, command=clean_value)
# b1.pack()
# b2.pack()
###
top.mainloop()