from tkinter import *
import requests
root=Tk()
def get_weather(city):
key = '68508284fb9247c6335d04f9fc158f12',
url = 'http://api.openweathermap.org/data/2.5/weather'
params = {'APPID': key, 'q': city, 'units': 'metric'}
result = requests.get(url, params=params)
weather = result.json()
saved_info = f'{weather["name"]}: {weather["main"]["temp"]}'
return saved_info
class City():
info=''
frame=Frame()
def __init__(self,info,frame):
self.info=info
self.frame=frame
def getTemp(self):
Label(text=self.info).pack(self.frame)
root.title("Weather Application")
root.geometry('500x300')
root.resizable(width=False,height=True)
root['bg']='#6896fc'
frame1=Frame(root,bg='#03ff00',bd=5)
frame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.15)
frame2=Frame(root,bg='#03ff00',bd=5)
frame2.place(relx=0.2,rely=0.27,relwidth=0.6,relheight=0.15)
frame3=Frame(root,bg='#03ff00',bd=5)
frame3.place(relx=0.2,rely=0.44,relwidth=0.6,relheight=0.15)
frame4=Frame(root,bg='#03ff00',bd=5)
frame4.place(relx=0.2,rely=0.61,relwidth=0.6,relheight=0.15)
frame5=Frame(root,bg='#03ff00',bd=5)
frame5.place(relx=0.2,rely=0.78,relwidth=0.6,relheight=0.15)
a=City(get_weather('Almaty'),frame1)
a1=City(get_weather('Astana'),frame2)
n=City(get_weather('New York'),frame3)
d=City(get_weather('Dubai'),frame4)
p=City(get_weather('Paris'),frame5)
a1.getTemp()
a.getTemp()
n.getTemp()
p.getTemp()
d.getTemp()
root.mainloop()
Нужно сделать GUI программу,которая выводит температуру 5 любых городов в 5 Label'х в питоне
Можно использовать только:Tkinter,requests,классы,функции,и то-что знакомо начинающим
Вот ошибки,если надо:
Traceback (most recent call last):
File "C:\Users\...\PycharmProjects\pythonProject\Lesson1\beginning.py", line 40, in
a1.getTemp()
File "C:\Users\...\PycharmProjects\pythonProject\Lesson1\beginning.py", line 20, in getTemp
Label(text=self.info).pack(self.frame)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2398, in pack_configure
+ self._options(cnf, kw))
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1473, in _options
cnf = _cnfmerge(cnf)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 109, in _cnfmerge
for c in _flatten(cnfs):
TypeError: object of type 'Frame' has no len()
import requests
import threading
def test():
root.after(1000, test)
threading.Thread(target=test1).start()
def test1():
r = requests.get('https://time100.ru/api.php').json()
label['text'] = r
root = Tk()
label = Label()
label.pack()
btn = Button(text="КНОПКА")
btn.pack()
test()
root.mainloop()