制作一个刷新按钮



我想做一个刷新按钮来实现API的信息,但不知道如何实现,我想实现的代码如下:

def templ(widget):
global templl,varil
templl=Gtk.Window(title='Weather City Of London')
varil=0
print('ver')
print(varil)
while varil==0:
requisicao3=requests.get('http://api.openweathermap.org/data/2.5/weather?q=City of London&appid=a5d84c2b0dbdc187d1521773a2bd3a22')
tempo3=json.loads(requisicao3.text)
reqt3=(tempo3['weather'][0]['main'])
atl3=Gtk.Button("atualize")
print(reqt3)
vbox3=Gtk.VBox()
templl.add(vbox3)
templl.add(vbox3)
lblreqt3=Gtk.Label(reqt3)
vbox3.add(lblreqt3)
vbox3.add(atl3)
templl.set_default_size(640,480)
templl.show_all()
varil=0
print("funcionalop")
londonb.connect("clicked",templ)

下面是一个函数,当被调用时,它会获取天气并将其放在窗口中。它与按钮相连。

# widget setup
def fetch_weather(widget):
requisicao3 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=City of London&appid=a5d84c2b0dbdc187d1521773a2bd3a22')
tempo3 = json.loads(requisicao3.text)
reqt3 = tempo3['weather'][0]['main']
lblreqt3.set_label(reqt3)
if should_fetch_before_show:
fetch_weather(atl3)
atl3.connect("clicked", fetch_weather)
# show the window

最新更新