-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (34 loc) · 1.43 KB
/
app.py
File metadata and controls
44 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import tkinter as tk
import requests
import time
import constants
def getWeather():
city = textField.get()
apiUrl = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={constants.OPENWEATHER_APIKEY}"
json_data = requests.get(apiUrl).json()
condition = json_data['weather'][0]['main']
temp = int(json_data['main']['temp'] - 273.15)
min_temp = int(json_data['main']['temp_min'] - 273.15)
max_temp = int(json_data['main']['temp_max'] - 273.15)
pressure = json_data['main']['pressure']
humidity = json_data['main']['humidity']
wind = json_data['wind']['speed']
final_info = condition + "\n" + str(temp) + "°C"
final_data = "\n"+ "Min Temp: " + str(min_temp) + "°C" + "\n" + "Max Temp: " + str(max_temp) + "°C" +"\n" + "Pressure: " + str(pressure) + "\n" +"Humidity: " + str(humidity) + "\n" +"Wind Speed: " + str(wind)
label1.config(text = final_info)
label2.config(text = final_data)
canvas = tk.Tk()
canvas.geometry("600x500")
canvas.title("Weather App")
smallText = ("poppins", 15, "bold")
largeText = ("poppins", 35, "bold")
textField = tk.Entry(canvas, justify='center', width = 20, font = largeText)
submitButton = tk.Button(canvas, text="Get Result", command=getWeather)
textField.pack(pady = 20)
submitButton.pack(pady = 15)
textField.focus()
label1 = tk.Label(canvas, font=largeText)
label1.pack()
label2 = tk.Label(canvas, font=smallText)
label2.pack()
canvas.mainloop()