Upload
vishwas-reddy
View
229
Download
0
Embed Size (px)
Citation preview
7/28/2019 Python_Gui_ppt
1/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Under the guidance of
Dr. Kota Solomon Raju
Principal Scientist
Presented By
Python Introduction
VISHWAS REDDYProject Trainee
Digital System Group
7/28/2019 Python_Gui_ppt
2/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
OBJECTIVE
To create a GUI automated applicatiPartial Reconfigurable Region Desig
7/28/2019 Python_Gui_ppt
3/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
CONTENTS
1)What is python
2)Properties
3)What is it used for?
4)Who is using it ?5)Python GUI Programming(tkinter)
6)Example
7/28/2019 Python_Gui_ppt
4/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
What is Python?
Python is a high-level, interpreted, interactive and object oriented-scripting la
was designed to be highly readable which uses English keywords frequently
languages use punctuation and it has fewer syntactical constructions than ot
Python is Interpreted: This means that it is processed at runtime by the inte
do not need to compile your program before executing it. This is similar to PE
Python is Interactive: This means that you can actually sit at a Python prom
with the interpreter directly to write your programs.
Python is Object-Oriented: This means that Python supports Object-Orienttechnique of programming that encapsulates code within objects.
7/28/2019 Python_Gui_ppt
5/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Properties
Open Source (OSI Certified)
copyrighted but use not restricted
no "viral" license owned by independent non-profit, PSF
Extremely portable
Unix/Linux, Windows, Mac, PalmOS, WindowsCE, RiscOS, VxWorks, Q
OS/390, AS/400, PlayStation, Sharp Zaurus, BeOS, VMS
Compiles to interpreted byte code
compilation is implicit and automatic
Memory management automatic
reference counting for most situations
GC added for cycle detection
Safe: no core dumps due to your bugs
7/28/2019 Python_Gui_ppt
6/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
What is it used for?
Rapid Prototyping
Web Programming (client and server side)
Ad Hoc Programming ("scripting")
Steering Scientific Applications
Extension Language
XML Processing
Database Applications
GUI Applications
Education
7/28/2019 Python_Gui_ppt
7/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Rapid Prototyping
Rapid Prototyping (RP) can be defined as a group of techniques
used to quickly fabricate a scale model of a part or assembly using three-dimens
computer aided design (CAD) data.
Why prototyping?The reasons of Rapid Prototyping are
To increase effective communication.
To decrease development time.
To decrease costly mistakes.
To minimize sustaining engineering changes.
To extend product lifetime by adding necessary features and eliminating redund
early in the design.
Image Source : http://en.wikiversity.org
7/28/2019 Python_Gui_ppt
8/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Web Browsing
What is CGI ?
The Common Gateway Interface, or CGI, is a set of standards that define how
exchanged between the web server and a custom script.
The CGI specs are currently maintained by the NCSA and NCSA defines CG The Common Gateway Interface, or CGI, is a standard for external gateway p
interface with information servers such as HTTP servers.
The current version is CGI/1.1 and CGI/1.2 is under progress.
Web Browsing
To understand the concept of CGI, lets see what happens when we click a hy
browse a particular web page or URL. Your browser contacts the HTTP web server and demand for the URL ie. filen
Web Server will parse the URL and will look for the filename in if it finds that f
back to the browser otherwise sends an error message indicating that you hav
wrong file.
Web browser takes response from web server and displays either the receive
message.
7/28/2019 Python_Gui_ppt
9/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Ad Hoc Programming ("scripting")
Ad Hoc is a latin phrase meaning "for this". It generally signifies
designed for a specific problem or task, non-generalizable, and n
to be able to be adapted to other purposes (compare a proiri). Co
examples are organizations, committees, and commissions crea
national or international level for a specific task. In other fields th
refer, for example, to a military unit created under special circum
tailor-made suit, a handcrafted network protocal, or a purpose-
specific equation.Ad hoccan also mean makeshift solutions, sh
contexts to create new meanings, inadequate planning, or improevents.
7/28/2019 Python_Gui_ppt
10/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Steering Scientific Applications(1)
Scientists Are on the Move. During the last decade, the popularity of scienti
c computing environments such as Maple, Mathematica, Matlab, and SPlus/R has increased considerably. Scientists and engineers simply feel more
productive in such environments. One reason is the simple and clean syntax
of the command languages in these environments. Another factor is the tight
integration of simulation and visualization: in Maple, Matlab, S-Plus/R and
similar environments you can quickly and conveniently visualize what you
just have computed.
7/28/2019 Python_Gui_ppt
11/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Steering Scientific Applications(2)
Build Your Own Environment. One problem with the mentioned environments
is that they do not work, at least not in an easy way, with other typesof numerical software and visualization systems. Many of the environmentspeci
c programming languages are also quite simple or primitive. At this
point scripting in Python comes in. Python oers the clean and simple syntax
of the popular scientic computing environments, the language is very
powerful, and there are lots of tools for gluing your favorite simulation, visualizatio
and data analysis programs the way you want. Phrased dierently,
Python allows you to build your own Matlab-like scientic computing
environment, tailored to your specic needs and based on your favorite high perfo
Fortran, C, or C++ codes.
7/28/2019 Python_Gui_ppt
12/[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Steering Scientific Applications(3)
Graphical User Interfaces. GUIs are becoming increasingly more important
in scientic software, but (normally) computational scientists and engineershave neither the interest nor the time to read thick books about GUI programming
What you need is a quick \how-to" description of wrapping GUIs
to your applications. The Tk-based GUI tools available through Python make
it easy to wrap existing programs with a GUI
7/28/2019 Python_Gui_ppt
13/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Who is using it?
Google (various projects)
NASA (several projects) NYSE (one of only three languages "on the floor")
Industrial Light & Magic (everything)
Yahoo! (Yahoo mail & groups)
Real Networks (function and load testing)
RedHat (Linux installation tools)
LLNL, Fermilab (steering scientific applications)
Zope Corporation (content management)
Object Domain (embedded Jython in UML tool)
Alice project at CMU (accessible 3D graphics)
More success stories at www.pythonology.com
7/28/2019 Python_Gui_ppt
14/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Compiling and interpreting
Many languages require you to compile (translate) your program into a form th
machine understands.
Python is instead directly interpretedinto machine instructions
compile execute
outputsource codeHello.java
byte codeHello.class
interpret
outputsource codeHello.py
7/28/2019 Python_Gui_ppt
15/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python GUI Programming (Tkinte
Python provides various options for developing graphical u
interfaces (GUIs). Most important are listed below:
Tkinter: Tkinter is the Python interface to the Tk GUI toolk
with Python. We would look this option in this tutorial.
wxPython: This is an open-source Python interface for
wxWindows http://wxpython.org. JPython: JPython is a Python port for Java, which gives P
scripts seamless access to Java class libraries on the loca
machine http://www.jython.org.
http://wxpython.org/http://www.jython.org/http://www.jython.org/http://wxpython.org/7/28/2019 Python_Gui_ppt
16/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Tk Overview
Set of widgets designed by John K. Ousterhout, 1987
Based on Apple Hypercard idea of putting together graphics prog
Tk == Tool Kit
Mean to be driven by Tcl (Toolkit Control Language)
Many people find Tcl limited
Can also drive Tk with Perl, Python
Tkinter is the Python Tk Interface
Very easy to use
7/28/2019 Python_Gui_ppt
17/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Tkinter Programming:
Tkinter is the standard GUI library for Python. Python when combined with Tk
fast and easy way to create GUI applications. Tkinter provides a powerful objeinterface to the Tk GUI toolkit.
Creating a GUI application using Tkinter is an easy task. All you need to do is
following steps:
Example:Import the Tkintermodule.
Create the GUI application main window.
Add one or more of the above mentioned widgets to the GUI application.
Enter the main event loop to take action against each event triggered by t
import Tkinter
top = Tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
7/28/2019 Python_Gui_ppt
18/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
blabels
Entry
box
Compiler output
box
checkboxlis
Bullet
button
7/28/2019 Python_Gui_ppt
19/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Button
Python - Tkinter Button
The Button widget is used to add buttons in a Python application. These buttotext or images that convey the purpose of the buttons. You can attach a functi
to a button, which is called automatically when you click the button.
Syntax:
w = Button ( master, option=value, ... )
Parameters:
master: This represents the parent window. options: Here is the list of most commonly used options for this widget. T
can be used as key-value pairs separated by commas.
7/28/2019 Python_Gui_ppt
20/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example:
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
def helloCallBack():
tkMessageBox.showinfo( "Hello Python", "Hello World"
B = Tkinter.Button(top, text ="Hello", command =
helloCallBack)
B.pack()
top.mainloop()
7/28/2019 Python_Gui_ppt
21/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Checkbutton
The Checkbutton widget is used to display a number of options to a user as to
The user can then select one or more options by clicking the button corresponoption.
You can also display images in place of text.
Syntax:
w = Checkbutton ( master, option, ... )
Parameters:
master: This represents the parent window.
options: Here is the list of most commonly used options for this widget. T
can be used as key-value pairs separated by commas.
7/28/2019 Python_Gui_ppt
22/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example:
from Tkinter import *
import tkMessageBox
import Tkinter
top = Tkinter.Tk()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
C1 = Checkbutton(top, text = "Music", variable = CheckVar1, \
onvalue = 1, offvalue = 0, height=5, width = 20)
C2 = Checkbutton(top, text = "Video", variable = CheckVar2, \
onvalue = 1, offvalue = 0, height=5, width = 20)
C1.pack()
C2.pack()
top.mainloop()
7/28/2019 Python_Gui_ppt
23/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Entry:
The Entry widget is used to accept single-line text strings from a user.
If you want to display multiple lines of text that can be edited, then you should usethe
If you want to display one or more lines of text that cannot be modified by the user the
the Labelwidget.
Syntax:
Here is the simple syntax to create this widget:
w = Entry( master, option, ... )
Parameters:
master: This represents the parent window. options: Here is the list of most commonly used options for this widget. These op
used as key-value pairs separated by commas.
7/28/2019 Python_Gui_ppt
24/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Examplefrom Tkinter import *
top = Tk()
L1 = Label(top, text="User Name")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)
top.mainloop()
7/28/2019 Python_Gui_ppt
25/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Label
This widget implements a display box where you can place text or images. Th
displayed by this widget can be updated at any time you want.
It is also possible to underline part of the text (like to identify a keyboard short
the text across multiple lines.
Syntax:
Here is the simple syntax to create this widget:
w = Label ( master, option, ... )
Parameters:
master: This represents the parent window.
options: Here is the list of most commonly used options for this widget. T
can be used as key-value pairs separated by commas.
7/28/2019 Python_Gui_ppt
26/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example:
from Tkinter import *
root = Tk()
var = StringVar()
label = Label( root, textvariable=var, relief=RAISED )
var.set("Hey!? How are you doing?")label.pack()
root.mainloop()
7/28/2019 Python_Gui_ppt
27/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Listbox
The Listbox widget is used to display a list of items from which a user can sele
items
Syntax:
Here is the simple syntax to create this widget:
w = Listbox ( master, option, ... )
Parameters:
master: This represents the parent window.
options: Here is the list of most commonly used options for this widget. Tcan be used as key-value pairs separated by commas.
E l
7/28/2019 Python_Gui_ppt
28/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example:from Tkinter import *
import tkMessageBox
import Tkinter
top = Tk()
Lb1 = Listbox(top)
Lb1.insert(1, "Python")
Lb1.insert(2, "Perl")
Lb1.insert(3, "C")
Lb1.insert(4, "PHP")Lb1.insert(5, "JSP")
Lb1.insert(6, "Ruby")
Lb1.pack()
top.mainloop()
P th Tki t R di b tt
7/28/2019 Python_Gui_ppt
29/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Radiobutton
This widget implements a multiple-choice button, which is a way to offer many
selections to the user, and let user choose only one of them.
In order to implement this functionality, each group of radiobuttons must be as
same variable, and each one of the buttons must symbolize a single value. Yo
Tab key to switch from one radionbutton to another.
Syntax:
Here is the simple syntax to create this widget:
w = Radiobutton ( master, option, ... )
Parameters:
master: This represents the parent window.
options: Here is the list of most commonly used options for this widget. T
can be used as key-value pairs separated by commas.
E l
7/28/2019 Python_Gui_ppt
30/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Examplefrom Tkinter import *
def sel():
selection = "You selected the option " + str(var.get())
label.config(text = selection)
root = Tk()var = IntVar()
R1 = Radiobutton(root, text="Option 1", variable=var,
value=1, command=sel)
R1.pack( anchor = W )
R2 = Radiobutton(root, text="Option 2", variable=var,
value=2,command=sel)
R2.pack( anchor = W )
R3 = Radiobutton(root, text="Option 3", variable=var,
value=3,command=sel)
R3.pack( anchor = W)
label = Label(root)
label.pack()
root.mainloop()
P th Tki t S llb
7/28/2019 Python_Gui_ppt
31/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Scrollbar
This widget provides a slide controller that is used to implement vertical scroll
such as Listbox, Text, and Canvas. Note that you can also create horizontal s
Entry widgets.
Syntax:
Here is the simple syntax to create this widget:
w = Scrollbar ( master, option, ... )
Parameters:
master: This represents the parent window.
options: Here is the list of most commonly used options for this widget. T
can be used as key-value pairs separated by commas.
E l
7/28/2019 Python_Gui_ppt
32/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example
from Tkinter import *
root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )
mylist = Listbox(root, yscrollcommand = scrollbar.set )
for line in range(100):
mylist.insert(END, "This is line number " + str(line))
mylist.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = mylist.yview )
mainloop()
Python Tkinter Message
7/28/2019 Python_Gui_ppt
33/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Python - Tkinter Message
This widget provides a multiline and noneditable object that displays texts, automatica
and justifying their contents.
Its functionality is very similar to the one provided by the Label widget, except that it ca
automatically wrap the text, maintaining a given width or aspect ratio.
Syntax:
Here is the simple syntax to create this widget:
w = Message ( master, option, ... )
Parameters:
master: This represents the parent window.
options: Here is the list of most commonly used options for this widget. These op
used as key-value pairs separated by commas.
Example:
7/28/2019 Python_Gui_ppt
34/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example:
from Tkinter import *
root = Tk()
var = StringVar()
label = Message( root, textvariable=var, relief=RAISED )
var.set("Hey!? How are you doing?")label.pack()
root.mainloop()
Compared to Perl
7/28/2019 Python_Gui_ppt
35/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Compared to Perl
Easier to learn
especially for infrequent users More readable code
improved code maintenance
Fewer magical side effects
More safety guarantees
Better Java integration Some things slower
Compared to Java
7/28/2019 Python_Gui_ppt
36/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Compared to Java
Code 5-10 times more concise
Dynamic typing Much quicker development
no compilation phase
less typing
Yes, it runs slower
but development is much faster!Ditto (but more so) for C/C++
Compared to Tcl
7/28/2019 Python_Gui_ppt
37/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Compared to Tcl
Real datatypes, object-orientation
More differentiated syntax Much faster (even than Tcl 8.0)
Can use threads
Less need for C extensions
hence fewer extension conflicts
Better Java integration Python uses Tk as de-facto GUI std
JPython
7/28/2019 Python_Gui_ppt
38/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
JPython
Seamless integration with Java
Separate implementation classic Python called CPython here
Implements the same language
Different set of standard modules
differences in gray areas
e.g. some different introspection calls different command line options, etc.
Java integration
7/28/2019 Python_Gui_ppt
39/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Java integration
Interactive
Compiles direct to Java bytecode Import Java classes directly
Subclass Java classes
pass instances back to Java
Java beans integration
Can compile into Java class files run as applet in browsers
Example
7/28/2019 Python_Gui_ppt
40/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Example
7/28/2019 Python_Gui_ppt
41/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Recommended Referals
7/28/2019 Python_Gui_ppt
42/42
[email protected] /[email protected], CSIR-CEERI RCS & WSN Labs, Digital Systems Group, CSIR-CEERI, PILANI-333031(Raj),Ind
Recommended Referals
http://en.wikipedia.org/wiki/Python_(programming_language)
Http://web.media.mit.edu/~dustin/books/pycs.pdf
http://en.wikipedia.org/wiki/Rapid_application_development
https://cs.american.edu/~fleck/classes/csc280/spring11/slides/tkinter.ppt
http://www.tutorialspoint.com/
http://en.wikipedia.org/wiki/Python_(programming_language)http://web.media.mit.edu/~dustin/books/pycs.pdfhttp://en.wikipedia.org/wiki/Rapid_application_developmenthttps://cs.american.edu/~fleck/classes/csc280/spring11/slides/tkinter.ppthttp://www.tutorialspoint.com/http://www.tutorialspoint.com/https://cs.american.edu/~fleck/classes/csc280/spring11/slides/tkinter.ppthttp://en.wikipedia.org/wiki/Rapid_application_developmenthttp://web.media.mit.edu/~dustin/books/pycs.pdfhttp://en.wikipedia.org/wiki/Python_(programming_language)