i wrote a programm, that gets weather data from a api, and now im working on a interface, but when i want a new temperature in the same label it doesnt work.
import requests
from tkinter import *
global stadt
TOKEN = "rrrrrrrrrr"
a = "jaaa"
root = Tk()
root.title("Wetter")
root.geometry("300x150")
def get_entry():
stadt = Entry1.get()
url = f"https://api.openweathermap.org/data/2.5/weather?q={stadt}&appid={TOKEN}"
f = requests.get(url).json()
temperatur = f["main"]["temp"]
temperatur = temperatur - 273.15
luftdruck = f["main"]["pressure"]
alltext= f"Die Temperatur in {stadt} beträgt {round(temperatur)}°C\nDer Luftdruck in {stadt} beträgt {luftdruck}Ba"
string = StringVar()
lab = Label(root, text=alltext)
lab.pack()
string.set(alltext)
Label1 = Label(root, text="Bitte Stadt eingeben")
Label1.pack()
Entry1 = Entry(root)
Entry1.pack()
Button1 = Button(root, text="Senden", command=get_entry)
Button1.pack()
root.mainloop()
"""temperatur = u[2][2]
luftdruck = u[2][4]
temperatur = temperatur -273.15
print("Temperatur = ",round(temperatur),"°C")
print("Luftdruck = ",round(luftdruck),"Pa")
my goal is to update a label, without creating the same label again
on the picutre you can see the problem, i want it so that the text overwrites other one
source https://stackoverflow.com/questions/71164869/how-to-update-a-tkinter-label
Comments
Post a Comment