You are on page 1of 17

Weather Forecasting Application in Python

(Using Tkinter GUI)

A six week industrial training report submitted in the partial


fulfillment of the requirement for the award of degree of
Bachelor of Technology (Computer Science & Engineering)

(Session: 2016-2020)

Submitted to: Submitted by:


Ms. Saumya Akash Dhoundiyal
CSE Department 251602062
UIET, KUK CSE – A

University Institute of Engineering and Technology


Kurukshetra University, Kurukshetra – 136119
DECLARATION
I AKASH DHOUNDIYAL , student of Bachelor of Technology (Computer
Science & Engineering), in the Department of Computer Science &
Engineering, University institute of Engineering and Technology,
Kurukshetra University, Kurukshetra, under class Roll No. 251602062 for
the session 2016-2020, hereby, declare that the report entitled “WEATHER
FORECAST APPLICATION ” has been completed by me After 6th semester.I
hereby declare, on behalf of myself that:

i. The matter embodied in this Dissertation is an original work and


has not been submitted earlier for award of any degree or diploma
to the best of my knowledge and belief. Moreover, the Dissertation
does not breach any existing copyright or any other third party
rights.
ii. The Dissertation contains no such material that may be illegal and
offensive.

I hereby agree to indemnify UIET and its Teaching Staff against any and all
losses incurred in connection with any claim or proceeding assert
plagiarism and/or copyright infringement if the investigation carried out to
determines that my work is the plagiarizing or infringing work.

Date: 30th July,2019 (AKASH)


Table of Contents

S. Topic
No.
1. certificate

2. Abstract

3. History of python

4. Why python?

5. Characterstics of python programming

6. Data structures in python

7. Use of Numpy , Pandas And GUI tkinter libraries

8. Requirements & Specification

9. Weather forecasting app. working

10. Conclusion
Abstract
Python program to create a Weather Forecast Application using Python
Programming concepts And Tkinter GUI to develop Application .
This is a project report on “WEATHER FORECAST”’ using openweathermap
API.It is a service that provides weather data,including current weather
data,forecasts,and historical data to the developer of web services and
mobile application.It provides an API with JSON,XML and HTML formats.
To use this current weather data API,one must need the API key,User need
to create an account on openweathermap.org then only can use the
APIs.we use two modules in the program requests And Json.

Application Programming Interface(API):


It is a set of protocols,routines,functions and/or commands that
programmers use to develop software or fascilitate interaction between
distinct systems.APIs are available for both desktop and mobile use, and
are typically useful for programming GUI (graphic user interface)
components, as well as allowing a software program to request and
accommodate services from another program.

Python GUI Tkinter:


Python offers multiple options for developing GUI (Graphical User
Interface). Out of all the GUI methods, tkinter is most commonly used
method. It is a standard Python interface to the Tk GUI toolkit shipped
with Python. Python with tkinter outputs the fastest and easiest way to
create the GUI applications. Creating a GUI using tkinter is an easy task.
HISTORY OF PYTHON
Python was developed in 1980 by Guido van Rossum at the National
Research Institute for Mathematics and Computer Science in the
Netherlands as a successor of ABC language capable of exception handling
and interfacing. Python features a dynamic type system and automatic
memory management. It supports multiple programming paradigms,
including object-oriented, imperative, functional and procedural, and has
a large and comprehensive standard library.
Van Rossum picked the name Python for the new language from a TV
show, Monty Python's Flying Circus.
In December 1989 the creator developed the 1st python interpreter as a
hobby and then on 16 October 2000, Python 2.0 was released with many
new features.
...In December 1989, I was looking for a "hobby" programming project
that would keep me occupied during the week around Christmas. My
office ... would be closed, but I had a home computer, and not much else
on my hands. I decided to write an interpreter for the new scripting
language I had been thinking about lately: a descendant of ABC that
would appeal to Unix/C hackers. I chose Python as a working title for the
project, being in a slightly irreverent mood (and a big fan of Monty
Python's Flying Circus)

— Guido van Rossum


Why Python ?
The language's core philosophy is summarized in the document The Zen of
Python (PEP 20), which includes aphorisms such as…
 Beautiful is better than ugly
 Simple is better than complex
 Complex is better than complicated
 Readability counts
 Explicit is better than implicit

A simple program to print “HELLO WORLD” :


Characteristics of Python

 Interpreted Language: Python is processed at runtime by Python


Interpreter
• Easy to read: Python source-code is clearly defined and visible to the
eyes.
• Portable: Python codes can be run on a wide variety of hardware
platforms having the same interface.
• Extendable: Users can add low level-modules to Python interpreter.
 Scalable: Python provides an improved structure for supporting large
programs than shell-scripts.
• Object-Oriented Language: It supports object-oriented features and
techniques of programming.
• Interactive Programming Language: Users can interact with the python
interpreter directly for writing programs.
• Easy language: Python is easy to learn language especially for
beginners.
• Straight forward Syntax: The formation of python syntax is simpleand
straightforward which also makes it popular.
Data Structures in Python

LISTS-
 Ordered collection of data.
 Supports similar slicing and indexing functionalities as in the case of
Strings.
 They are mutable.
 Advantage of a list over a conventional array
• Lists have no size or type constraints(no setting restrictions
beforehand).
• They can contain different object types.
• We can delete elements from a list by using Del
list_name[index_val]

 Example-
• my_list = ['one', 'two','three',4,5]
• len(my_list) would output 5.

Dictionary-
 Lists are sequences but the dictionaries are mappings.
 They are mappings between a unique key and a value pair.
 These mappings may not retain order.
 Constructing a dictionary.
 Accessing object from a dictionary.
 Nesting Dictionaries.
 Basic Dictionary Methods.

 Basic Syntax :
o d={} empty dictionary will be generated and assign keys
and values to it, like d[‘animal’] = ‘Dog’
o d = {'K1':'V1', 'K2’:’V2'}
o d['K1'] outputs 'V1
Tuples-
 Immutable in nature, i.e they cannot be changed.
 No type restriction .
 Indexing and slicing, everything's same like that in strings and lists.
 Constructing tuples.
 Basic tuple methods.
 Immutability.
 When to use tuples?
 We can use tuples to present things that shouldn’t change, such as
days of the week, or dates on a calendar, etc.

Sets-
 A set contains unique and unordered elements and we can
construct them by using a set() function.
 Convert a list into Set-
 l=[1,2,3,4,1,1,2,3,6,7]
 k = set(l)
 k becomes {1,2,3,4,6,7}
 Basic Syntax-
 x=set()
 x.add(1)
 x = {1}
 x.add(1)
 This would make no change in x now
Use of Numpy
NumPy is a Python package. It stands for 'Numerical Python'. It is a library
consisting of multidimensional array objects and a collection of routines for
processing of array.
Numeric, the ancestor of NumPy, was developed by Jim Hugunin. Another
package Numarray was also developed, having some additional
functionalities. In 2005, Travis Oliphant created NumPy package by
incorporating the features of Numarray into Numeric package. There are
many contributors to this open source project.
Operations using NumPy Using NumPy, a developer can perform the
following operations −
 Mathematical and logical operations on arrays.
 Fourier transforms and routines for shape manipulation.
 Operations related to linear algebra. NumPy has in-built
functions for linear algebra and random number generation.
Simple program to create a matrix-
First of all we import numpy package then using this we take input in numpy
function as a list then we create a matrix

There is many more function can be perform by using this like that take sin
value of the given value ,print a zero matrix etc. we also take any image in
the form of array.
Use of Pandas
Pandas is an open-source, BSD-licensed Python library providing
highperformance, easy-to-use data structures and data analysis tools for the
Python programming language. Python with Pandas is used in a wide range
of fields including academic and commercial domains including finance,
economics, Statistics, analytics, etc.
Pandas is an open-source Python Library providing high-performance data
manipulation and analysis tool using its powerful data structures. The name
Pandas is derived from the word Panel Data – an Econometrics from
Multidimensional data.
Key Features of Pandas-
• Fast and efficient DataFrame object with default and
Customized indexing.
 Tools for loading data into in-memory data objects from different
file formats.
 Data alignment and integrated handling of missing data.
 Reshaping and pivoting of date sets.
 Label-based slicing, indexing and subsetting of large data sets.
 Columns from a data structure can be deleted or inserted.
 Group by data for aggregation and transformations.
Pandas deals with the following three data structures –
 Series
 DataFrame
 Panel
These data structures are built on top of Numpy array, which means they
are fast.
Tkinter – GUI in Python
Python offers multiple options for developing GUI (Graphical User Interface).
Out of all the GUI methods, tkinter is most commonly used method. It is a
standard Python interface to the Tk GUI toolkit shipped with Python. Python
with tkinter outputs the fastest and easiest way to create the GUI
applications. Creating a GUI using tkinter is an easy task.
To create a tkinter:
1. Importing the module – tkinter
2. Create the main window (container)
3. Add any number of widgets to the main window
4. Apply the event Trigger on the widgets.

Importing tkinter is same as importing any other module in the python code.
Note that the name of the module in Python 2.x is ‘Tkinter’ and in Python 3.x
is ‘tkinter’.
*Import tkinter
There are two main methods used you the user need to remember while
creating the Python application with GUI.
1. Tk(screenName=None, baseName=None, className=’Tk’, useTk=1:
To create a main window, tkinter offer a
methodTk(screenName=None, baseName=None, className=’Tk’, useTk
=1). To change the name of the window, you can change the className to
the desired one. The basic code used to create the main window of the
application is:
m=tkinter.Tk() where m is the name of the main window object
2.mainloop(): There is a method known by the name mainloop() is used
when you are ready for the application to run. mainloop() is an infinite
loop used to run the application, wait for an event to occur and process
the event till the window is not closed.
m.mainloop()
import tkinter
m = tkinter.Tk()
'''
widgets are added here
'''
m.mainloop()
tkinter also offers access to the geometric configuration of the widgets
which can organize the widgets in the parent windows. There are mainly
three geometry manager classes class.
1. pack() method:It organizes the widgets in blocks before placing in the
parent widget.
2. grid() method:It organizes the widgets in grid (table-like structure)
before placing in the parent widget.
3. place() method:It organizes the widgets by placing them on specific
positions directed by the programmer.

There are a number of widgets which you can put in your tkinter
application. Some of the major widgets are explained below:
1. Button
2. Canvas
3. Checkbutton
4. Entry
5. Frame
6. Label
7. Listbox
8. MenuButton
Requirement And Specification

Hardware Requirements:

Processor : Pentium IV(minimum)


Hard Disk : 40GB
RAM : 256MB (minimum)

Software Requirements:

Operating System :
Windows Technology :
PYTHON
IDE Used : Pycharm Community 2019.1.3x64
Weather Forecasting App Working

How to start:
It is quite easy to work with Openweather API. Just sign up to get your API
key and then call any weather API. And mind using API key in every API call
whatever account you choose from Free to Enterprise.
How to start in 3 simple steps
1 Open Openweathermap website: https://openweathermap.org/appid
2 Sign up and get an API key (APPID) on your account page.
After registration, we will send you a welcome email that contain your API
key and additional information on how to get started with our weather
APIs. Within the next couple of hours, it will be activated and ready to use.
3 Start using API for free.
Find the complete description of API calls with a list of parameters and
examples of responses in API documentation.
Please, use API key in each API call.

Example of using API key in API call


Description:
Please, use your API key in each API call.
We do not process API requests without the API key.
API call:
http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID={APIKEY}

Parameters:
APPID {APIKEY} is your unique API key

Example of API call:


api.openweathermap.org/data/2.5/forecast?id=524901&APPID=1111111111
Python|Weather Forecasting Application using Tkinter
Python offers multiple options for developing GUI (Graphical User
Interface). Out of all the GUI methods, tkinter is the most commonly used
method. It is a standard Python interface to the Tk GUI toolkit shipped
with Python. Python with tkinter outputs the fastest and easiest way to
create the GUI applications. Now, it’s upto the imagination or necessity of
developer, what he/she want to develop using this toolkit.
To create a tkinter :
 Importing the module – tkinter
 Create the main window (container)
 Add any number of widgets to the main window.
 Apply the event Trigger on the widgets.
Let’s create a GUI based simple Real-time Weather detection application
which can give Weather details of any cities.
Modules required:
tkinter
requests
json

Program Code link:


https://drive.google.com/file/d/113iqGSwgsH4TljMnces-
GRx6z1PBGtUy/view

Application GUI:
Conclusion
The Project has been successfully completed by having established the
user friendly interface with the help of python tkinter library. At the
same time there is some scope for improvements in the future. It can
be possible to make it more Attractive by adding more variety of
functions . This application may helpful for the humans as it show the
weather details of a city.
I believe the trial has shown conclusively that it is both possible and
desirable to use Python as the principal teaching language:
• It is Free (as in both cost and source code).
• It is trivial to install on a Windows PC allowing students to take their
interest further. For many the hurdle of installing a Pascal or C
compiler on a Windows machine is either too expensive or too
complicated;
Future Scope:
 The Complicated equation which govern how the state of fluid
changes with time require super computer to solve them.
 The numerical weather prediction model are computer
similuation of the atmosphere .
 The output from the model provides the basis of the weather
forecast.
 Location and voice handling can be integrated with the weather
API.
The training program having three destination was a lot more useful
than staying at one place throughout the whole 6 weeks. In my
opinion. I have gained lots of knowledge and experience needed to be
successful in great engineering challenge as in my opinion, Engineering
is after all a Challenge ,and not a job .

Thankyou

You might also like