Zurück
Wetter App by Bekim Jahmurataj
main.py
from tkinter import *
import tkinter as tk
from geopy.geocoders import Nominatim
from tkinter import ttk, messagebox
from timezonefinder import TimezoneFinder
from datetime import datetime
import requests
import pytz
root = Tk()
root.title("Wetter App by Bekim Jahmurataj")
root.geometry("900x500+300+200")
root.resizable(False, False)
def getWeather():
city = textfield.get()
geolocator = Nominatim(user_agent="geoapiExercises")
location = geolocator.geocode(city)
obj = TimezoneFinder()
result = obj.timezone_at(lng=location.longitude, lat=location.latitude)
home = pytz.timezone(result)
local_time = datetime.now(home)
current_time = local_time.strftime("%I:%M %p")
clock.config(text=current_time)
name.config(text="CURRENT WEATHER")
#weather
api = "https://api.openweathermap.org/data/2.5/weather?q="+city+"&appid=4577f40f03593d52e9a3ae81cf04a517"
response = requests.get(api)
data = response.json()
try:
temperature = data["main"]["temp"] - 273.15
weather_desc = data["weather"][0]["description"]
wind_speed = data["wind"]["speed"] * 3.6
humidity = data["main"]["humidity"]
pressure = data["main"]["pressure"]/100
windchill = 13.12 + 0.6215 * temperature - 11.37 * (wind_speed ** 0.16) + 0.3965 * temperature * (wind_speed ** 0.16)
t.config(text=str(round(temperature, 1)) + " °C")
c.config(text=weather_desc + " | gefühlt wie " + str(round(windchill, 1)) + " °C")
w.config(text=str(round(wind_speed, 1)) + " km/h")
h.config(text=str(humidity) + " %")
d.config(text=weather_desc)
p.config(text=str(round(pressure, 1)) + " mbar")
except KeyError:
messagebox.showerror("Fehler", "Stadt nicht gefunden.")
# Suche
Search_image = PhotoImage(file="img/suche.png")
myimage = Label(image=Search_image)
myimage.place(x=20, y=20)
textfield = tk.Entry(root, justify="center", width=17, font=("poppins", 25, "bold"), bg="#404040", border=0, fg="white")
textfield.place(x=50, y=40)
textfield.focus()
Search_icon = PhotoImage(file="img/loope.png")
myimage_icon = Button(image=Search_icon, borderwidth=0, cursor="hand2", bg="#404040", command=getWeather)
myimage_icon.place(x=400, y=34)
# logo
Logo_image = PhotoImage(file="img//logo.png")
logo = Label(image=Logo_image)
logo.place(x=150, y=100)
# Bottom Box
Frame_image = PhotoImage(file="img/box.png")
frame_myimage = Label(image=Frame_image)
frame_myimage.pack(padx=5, pady=5, side=BOTTOM)
# time
name = Label(root, font=("arial", 12, "bold"))
name.place(x=30, y=100)
clock = Label(root, font=("Helvetica", 20))
clock.place(x=30, y=130)
# Label
label1 = Label(root, text="WIND", font=("Helvetica", 15, 'bold'), fg="white", bg="#1ab5ef")
label1.place(x=120, y=400)
label2 = Label(root, text="FEUCHTIGKEIT", font=("Helvetica", 15, 'bold'), fg="white", bg="#1ab5ef")
label2.place(x=270, y=400)
label3 = Label(root, text="BESCHREIBUNG", font=("Helvetica", 15, 'bold'), fg="white", bg="#1ab5ef")
label3.place(x=450, y=400)
label4 = Label(root, text="DRUCK", font=("Helvetica", 15, 'bold'), fg="white", bg="#1ab5ef")
label4.place(x=670, y=400)
t = Label(font=("arial", 70, "bold"), fg="#ee666d")
t.place(x=400, y=150)
c = Label(font=("arial", 15, 'bold'))
c.place(x=400, y=250)
w = Label(text="...", font=("arial", 20, "bold"), bg="#1ab5ef")
w.place(x=120, y=430)
h = Label(text="...", font=("arial", 20, "bold"), bg="#1ab5ef")
h.place(x=270, y=430)
d = Label(text="...", font=("arial", 20, "bold"), bg="#1ab5ef")
d.place(x=450, y=430)
p = Label(text="...", font=("arial", 20, "bold"), bg="#1ab5ef")
p.place(x=670, y=430)
root.mainloop()