├── README.md ├── LICENSE └── weather.py /README.md: -------------------------------------------------------------------------------- 1 | # Desktop-Weather-App 2 | A desktop app that informs weather of any place 3 | ## Getting started 4 | 5 | 1. get the code from the repository 6 | ``` 7 | git clone https://github.com/sagnikghoshcr7/Desktop-Weather-App.git 8 | ``` 9 | 2. install Thinker python package by the following command if previously not installed 10 | ``` 11 | pip install tkinker 12 | ``` 13 | 14 | 3. Finally run the weather.py file and enjoy 😉 15 | 16 | ![](https://github.com/sagnikghoshcr7/images/blob/master/Desktop%20Weather%20App.gif) 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Sagnik Ghosh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /weather.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import tkinter as tk 3 | from tkinter import font 4 | from PIL import Image,ImageTk 5 | 6 | root=tk.Tk() 7 | 8 | WIDTH=620 9 | HEIGHT=450 10 | 11 | 12 | def get_weather(city): 13 | weather_key="79de5817a4d223b536ce61a0f630a4b4" 14 | url='https://api.openweathermap.org/data/2.5/weather' 15 | params={'appid':weather_key, 'q':city, 'units':'Metric'} 16 | response=requests.get(url,params=params) 17 | report=response.json() 18 | 19 | label['text']=show_weather_report(report) 20 | 21 | 22 | def show_weather_report(report): 23 | try: 24 | city_name= report['name'] 25 | weather_condition= report['weather'][0]['description'] 26 | temp= report['main']['temp'] 27 | output= 'City: %s \nCondition: %s \nTemperature(°C): %s' %(city_name,weather_condition,temp) 28 | except: 29 | output='There was a problem while retrieving that information' 30 | return output 31 | 32 | 33 | canvas=tk.Canvas(root,width=WIDTH,height=HEIGHT) 34 | canvas.pack() 35 | 36 | 37 | frame=tk.Frame(root,bg='#0B90A9',bd=5) 38 | frame.place(relx=0.5,rely=0.1,relheight=0.1,relwidth=0.75,anchor='n') 39 | 40 | entry=tk.Entry(frame,font=('Courier New Baltic',20)) 41 | entry.place(relheight=1,relwidth=0.7) 42 | 43 | btn=tk.Button(frame,text="Get Weather",relief='raised',bg="gray",font=20,command=lambda: get_weather(entry.get())) 44 | btn.place(relx=0.72,relheight=1,relwidth=0.28) 45 | 46 | low_frame=tk.Frame(root,bg='#0B90A9',bd=5) 47 | low_frame.place(relx=0.5,rely=0.25,relheight=0.65,relwidth=0.75,anchor='n') 48 | 49 | bg_color='white' 50 | label=tk.Label(low_frame,font=('Calibri',20),justify='center',bd=4) 51 | label.config(font=40,bg=bg_color) 52 | label.place(relheight=1,relwidth=1) 53 | 54 | """ weather_icon=tk.Canvas(label,bg=bg_color,bd=0,highlightthickness=0) 55 | weather_icon.place(relx=0.75,rely=0,relwidth=1,relheight=0.5) """ 56 | 57 | 58 | root.mainloop() 59 | --------------------------------------------------------------------------------