SlideShare a Scribd company logo
RTS Tech 1
Agenda
 Introduction
 Top level widgets
 GUI widgets
 Event handling
 Application
RTS Tech 2
Graphical User Interface
RTS Tech 3
GUI Technologies
 Python provides many technology to create GUI.
 Some are as following
 Tkinter
 Tkinter is used to create desktop application.
 Wxpython
 wxPython is a cross-platform toolkit.
 Jpython
 Jython is a Java implementation of Python
RTS Tech 4
Tkinter
 Tkinter is inbuilt in python as an liabrary.
 We can create desktop application using tkinter module.
 Tkinter is easy to use.
 Tkinter provides fast way to create GUI.
 It is object based library to create GUI.
RTS Tech 5
How to get tkinter module
 If not installed in python package then we can install it
using pip command.
 pip install tkinter.
 We can import tkinter module.
 from tkinter import *
 Or
 import tkinter
RTS Tech 6
GUI widgets
 Label
 Entry
 Button
 Frame
 Menu
 Message
 Radio button
 checkbox
RTS Tech 7
GUI widgets
RTS Tech 8
Label
Frame
Entry
Button
Create First GUI
 Import tkinter module
 Create main window using Tk.
 Add widgets like buttons, Labels, Entry etc.
 Call main event loop.
RTS Tech 9
Create A Window
 from tkinter import *
 window = Tk()
 Label(window,text="Hello world“).pack()
 window.title(“First Frame")
 window.mainloop()
RTS Tech 10
Label widgets
 This is used to show text on the window.
 from tkinter import *
 main=Tk()
 label =Label(
 text="Hello, World",
 fg="white", # Set the text color to white
 bg="black" , # Set the background color to black
 font="bold", # Set the font
 width=10,#set the width
 height=3,#set the height
 ).pack()
 main.mainloop()
RTS Tech 11
Button
 Button is a label that we can click.
 from tkinter import *
 main=Tk()
 button=Button(
 text="Hello, World",
 fg="white", # Set the text color to white
 bg="black" , # Set the background color to black
 font="bold", # Set the font
 width=10,#set the width
 height=3,#set the height
 ).pack()
 main.mainloop()
RTS Tech 12
Get User input
 We can take user input using entry widgets.
 entry=Entry(
 fg="black", # Set the text color to white
 bg="Red" , # Set the background color to black
 font="bold",
 width=100,#set the width
 ).pack()
RTS Tech 13
Entry widgets Operation
 entry.get()
 To get user input
 entry.delete()
 To delete specific values of complete data
 entry.insert()
 To insert values.
RTS Tech 14
Entry Operations
 entry=Entry(
 fg="black", # Set the text color to white
 bg="Red" , # Set the background color to black
 font="bold",
 width=100,#set the width
 )
 entry.insert(0,"Python")
 name=entry.get()
 print(name)
 entry.delete(0)
 entry.pack()

RTS Tech 15
Text Widgets
 from tkinter import *
 main=Tk()
 text=Text(main).pack()
 main.mainloop()
 Text widgets are used to get multiline inputs
 Text widgets has same methods as entry widgets.
RTS Tech 16
Text Operations
 Text.insert(index,string)
 Text.delete(start_index,end_index)
 Text.get(strat_index, end _index)
RTS Tech 17
Get data from text widgets
 Text widgets contains multiline input, so we can not just pass a
single index like Entry widgets.
 We have to pass 2 arguments.
 Line no: starts with 1.
 Character index: starts with 0.
 Index is passed as the string as “<lineNo>.<index>”.
 To get 1st charcter of the 1st line
 Print(text.get("1.0")).
 To get all the data
 Print(text.get("1.0“,tkinter.END)).
RTS Tech 18
Frame Widgets
 It is a top level widget which contains other widgets.
 It is used to organize the layout of the widgets.
 It is used for the logical grouping of other widgets.
RTS Tech 19
Frame(cont.)
 from tkinter import *
 from tkinter import font
 window =Tk()
 frame1=Frame(window,width=100,height=50)
 frame2=Frame(window,width=100,height=50)
 label1=Label(frame1,bg="maroon",fg="white",text="Frame1”)
 label2=Label(frame2,bg="blue",fg="aqua",text="Frame2")
 label1.pack()
 label2.pack()
 frame1.pack()
 frame2.pack()
 window.mainloop()
RTS Tech 20
Create frame border
 We can create Frame border using relief attribute .
 The value for the relief attribute
 FLAT
 RIDGE
 SOLID
 GROOVE
 SUNKEN
 RAISED
RTS Tech 21
Frame types
 frame1=Frame(window,relief=FLAT,borderwidth=5)
 lb1=Label(frame1,text="Flat")

frame2=Frame(window,relief=RIDGE,borderwidth=5)
 lb2=Label(frame2,text="Ridge")

frame3=Frame(window,relief=SUNKEN,borderwidth=5)
 lb3=Label(frame3,text="sunken")
RTS Tech 22
Layout Management
 We can arrange the widgets in different layout.
 pack
 grid
 place
RTS Tech 23
Pack layout
 from tkinter import *
 window=Tk()
 b1=Button(window,text="Button 1",bg="red")
 b2=Button(window,text="Button 2",bg="Green")
 b3=Button(window,text="Button 3",bg="yellow")
 b4=Button(window,text="Button 4",bg="Orange")
 #layout
 b1.pack(side="top",fill=X)
 b2.pack(side="left",fill=Y)
 b3.pack(side="right",fill=Y)
 b4.pack(side="bottom",fill=X)
 window.mainloop()
RTS Tech 24
Place Layout
 from tkinter import *
 window=Tk()
 window.geometry("400x200")
 lb1=Label(window,text="Enter your name",font=30)
 e1=Entry(window)
 lb2=Label(window,text="Enter Password",font=30)
 e2=Entry(window)
 b1=Button(window,text="submit",font=30)
 lb1.place(x=20,y=20,height=20,width=150)
 lb2.place(x=20,y=50,height=20,width=150)
 e1.place(x=190,y=20,width=150)
 e2.place(x=190,y=50,width=150)
 b1.place(x=50,y=90,height=50,width=150)
 window.mainloop()
RTS Tech 25
Grid Layout
 from tkinter import *
 window=Tk()
 b1=Button(window,text="Button 1",bg="orange")
 b2=Button(window,text="Button
2",height=5,width=10,bg="yellow")
 b3=Button(window,text="Button
3",height=10,width=15,bg="red")
 b1.grid(row=0,column=0,ipadx=5,ipady=3)
 b2.grid(row=1,column=0,rowspan=2,ipadx=5,ipady=3)
 b3.grid(row=0,column=1,columnspan=2,rowspan=3,ipadx=5,ip
ady=3)
 window.mainloop()
RTS Tech 26
Event Handling
RTS Tech 27
Event Listeners
Events Description
<Button> A mouse button is pressed with the mouse
pointer over the widget
<FocusIn> Keyboard focus was moved to this widget,
<FocusOut> Keyboard focus was moved from this
widget to another widget
<Motion> The mouse is moved with a mouse button
being held down.
<Double Button> Similar to the Button event, see above, but
the button is double clicked instead of a
single click.
<key> Any key is pressed
RTS Tech 28
bind() function
 Bind function is used to bind the event to the
mainloop
 Bind takes 2 arguments
 An Event type
 An event handler Callback function name
 For ex.
 window.bind("<Button>",hello)
RTS Tech 29
Button Click Event
 from tkinter import *
 window =Tk()
 def hello(event):
 Label(window,text="Hello ").pack()
 btn=Button(window,text="Click
Me",font=40,bg="Red",fg='White')
 # btn1=Button(window,text="Click
Me",font=40,bg="Red",fg='White',command=hello)
 btn.pack()
 window.bind("<Button>",hello)
 window.mainloop()
RTS Tech 30
Mouse Motion Handler
 from tkinter import *
 window=Tk()
 def getPixel(event):
 s="x={} y={}".format(event.x, event.y)
 print(s)
 text="""This is a simple example of a
 event Handling in Tkinter.
 we are learning about Motion event.
 """
 msg=Message(window,text=text,bg="aqua",font=30)
 msg.pack(side="left")
 img=PhotoImage("indore.png",format="png")
 l1=Label(window,image=img)
 l1.pack(side="right")
 window.bind("<Motion>",getPixel)
 window.mainloop()
RTS Tech 31
An application(calculator)
 from tkinter import *
 window=Tk()
 window.title("Calculator")
 window.geometry("500x500")
 #input variables
 n1=StringVar()
 n2=StringVar()
 n3=StringVar()
 #callback functoin
 def add():
 a=int(n1.get())
 b=int(n2.get())
 n3.set("{}".format(a+b))
 def clr():
 n1.set("")
 n2.set("")
 n3.set("")
RTS Tech 32
Calculator(cont.)
 #create widgets
 l1=Label(window,text="Enter 1st Number",font=("Times",30))
 l2=Label(window,text="Enter 2nd Number",font=("Times",30))
 l3=Label(window,text="Result",font=("Times",30))

e1=Entry(window,textvariable=n1)
 e2=Entry(window,textvariable=n2)
 e3=Entry(window,textvariable=n3,readonlybackground="aqua")

b1=Button(window,text="Add",font=("Times",30),command=add)
 b2=Button(window,text="ClearText",font=("Times",30),command
=clr)
RTS Tech 33
Calculator(cont.)
 #manage layout
 l1.grid(row=0,column=0)
 l2.grid(row=1,column=0)
 l3.grid(row=2,column=0)

e1.grid(row=0,column=1)
 e2.grid(row=1,column=1)
 e3.grid(row=2,column=1)

b1.grid(row=3,column=0)
 b2.grid(row=3,column=1)
 window.mainloop()

RTS Tech 34
Disclaimer
 This is a educational Presentation to make
programming easier.
 We have used images of different URLs to make
presentation better.
 We respect the work of the owners of the URLs.
Thank You!
:rtstech30@gmail.com
:+91 8818887087
Disclaimer
 This is an educational presentation to enhance the
skill of computer science students.
 This presentation is available for free to computer
science students.
 Some internet images from different URLs are used
in this presentation to simplify technical examples
and correlate examples with the real world.
 We are grateful to owners of these URLs and
pictures.
RTS Tech 37
Ad

More Related Content

What's hot (20)

Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Python basics
Python basicsPython basics
Python basics
RANAALIMAJEEDRAJPUT
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAPYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
Maulik Borsaniya
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
Ilio Catallo
 
Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI Programming
Ranel Padon
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
Sourabh Sahu
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Advanced Python : Decorators
Advanced Python : DecoratorsAdvanced Python : Decorators
Advanced Python : Decorators
Bhanwar Singh Meena
 
Python cgi programming
Python cgi programmingPython cgi programming
Python cgi programming
Smt. Indira Gandhi College of Engineering, Navi Mumbai, Mumbai
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 

Similar to Python GUI Programming (20)

tkinterpptxguipythonImport it is named ‘tkinter
tkinterpptxguipythonImport  it is named ‘tkintertkinterpptxguipythonImport  it is named ‘tkinter
tkinterpptxguipythonImport it is named ‘tkinter
ssuser6bbf39
 
Tkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfTkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdf
ArielManzano3
 
Tkinter_GUI_Programming_in_ Python.pdf
Tkinter_GUI_Programming_in_    Python.pdfTkinter_GUI_Programming_in_    Python.pdf
Tkinter_GUI_Programming_in_ Python.pdf
AnmolMogalai
 
Tkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptxTkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptx
MohamedHany892810
 
Tkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptxTkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptx
MohamedHany892810
 
Design a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdfDesign a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdf
Footageetoffe16
 
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88
Mahmoud Samir Fayed
 
Char word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECTChar word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECT
MahmutKAMALAK
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptx
Mohamed Essam
 
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationCodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
Lee Stott
 
ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)
oudesign
 
Py-Slides-10.ppt Python Programming AIML
Py-Slides-10.ppt Python Programming AIMLPy-Slides-10.ppt Python Programming AIML
Py-Slides-10.ppt Python Programming AIML
webinartrainer
 
tkinter final ppt.ppt
tkinter final ppt.ppttkinter final ppt.ppt
tkinter final ppt.ppt
KanuAgrawal2
 
Python ppt
Python pptPython ppt
Python ppt
AMIT VIRAMGAMI
 
Python Programming
Python ProgrammingPython Programming
Python Programming
KennedyRodriguez4
 
Python.pdf textbooks content Artificical
Python.pdf textbooks content ArtificicalPython.pdf textbooks content Artificical
Python.pdf textbooks content Artificical
webinartrainer
 
Chapter - 6.pptx
Chapter - 6.pptxChapter - 6.pptx
Chapter - 6.pptx
MikialeTesfamariam
 
A Complete seminar on GUI Development in python
A Complete seminar on GUI Development in pythonA Complete seminar on GUI Development in python
A Complete seminar on GUI Development in python
18547Mymoon
 
wcmc_practicals
wcmc_practicalswcmc_practicals
wcmc_practicals
MannMehta7
 
Part 4 Introduction to Gui with tkinter
Part 4 Introduction to Gui with tkinterPart 4 Introduction to Gui with tkinter
Part 4 Introduction to Gui with tkinter
Mohamed Essam
 
tkinterpptxguipythonImport it is named ‘tkinter
tkinterpptxguipythonImport  it is named ‘tkintertkinterpptxguipythonImport  it is named ‘tkinter
tkinterpptxguipythonImport it is named ‘tkinter
ssuser6bbf39
 
Tkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfTkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdf
ArielManzano3
 
Tkinter_GUI_Programming_in_ Python.pdf
Tkinter_GUI_Programming_in_    Python.pdfTkinter_GUI_Programming_in_    Python.pdf
Tkinter_GUI_Programming_in_ Python.pdf
AnmolMogalai
 
Tkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptxTkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptx
MohamedHany892810
 
Tkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptxTkinter_GUI_Programming_in_Pythovvn.pptx
Tkinter_GUI_Programming_in_Pythovvn.pptx
MohamedHany892810
 
Design a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdfDesign a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdf
Footageetoffe16
 
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88
Mahmoud Samir Fayed
 
Char word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECTChar word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECT
MahmutKAMALAK
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptx
Mohamed Essam
 
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationCodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
Lee Stott
 
ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)ITS-16163-Module 8-Graphic User Interface (GUI)
ITS-16163-Module 8-Graphic User Interface (GUI)
oudesign
 
Py-Slides-10.ppt Python Programming AIML
Py-Slides-10.ppt Python Programming AIMLPy-Slides-10.ppt Python Programming AIML
Py-Slides-10.ppt Python Programming AIML
webinartrainer
 
tkinter final ppt.ppt
tkinter final ppt.ppttkinter final ppt.ppt
tkinter final ppt.ppt
KanuAgrawal2
 
Python.pdf textbooks content Artificical
Python.pdf textbooks content ArtificicalPython.pdf textbooks content Artificical
Python.pdf textbooks content Artificical
webinartrainer
 
A Complete seminar on GUI Development in python
A Complete seminar on GUI Development in pythonA Complete seminar on GUI Development in python
A Complete seminar on GUI Development in python
18547Mymoon
 
wcmc_practicals
wcmc_practicalswcmc_practicals
wcmc_practicals
MannMehta7
 
Part 4 Introduction to Gui with tkinter
Part 4 Introduction to Gui with tkinterPart 4 Introduction to Gui with tkinter
Part 4 Introduction to Gui with tkinter
Mohamed Essam
 
Ad

Recently uploaded (20)

Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Comprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptxComprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptx
dd7devdilip
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
How to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdfHow to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdf
jamedlimmk
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Novel Plug Flow Reactor with Recycle For Growth Control
Novel Plug Flow Reactor with Recycle For Growth ControlNovel Plug Flow Reactor with Recycle For Growth Control
Novel Plug Flow Reactor with Recycle For Growth Control
Chris Harding
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Comprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptxComprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptx
dd7devdilip
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
6th International Conference on Big Data, Machine Learning and IoT (BMLI 2025)
ijflsjournal087
 
How to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdfHow to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdf
jamedlimmk
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Novel Plug Flow Reactor with Recycle For Growth Control
Novel Plug Flow Reactor with Recycle For Growth ControlNovel Plug Flow Reactor with Recycle For Growth Control
Novel Plug Flow Reactor with Recycle For Growth Control
Chris Harding
 
Ad

Python GUI Programming

  • 2. Agenda  Introduction  Top level widgets  GUI widgets  Event handling  Application RTS Tech 2
  • 4. GUI Technologies  Python provides many technology to create GUI.  Some are as following  Tkinter  Tkinter is used to create desktop application.  Wxpython  wxPython is a cross-platform toolkit.  Jpython  Jython is a Java implementation of Python RTS Tech 4
  • 5. Tkinter  Tkinter is inbuilt in python as an liabrary.  We can create desktop application using tkinter module.  Tkinter is easy to use.  Tkinter provides fast way to create GUI.  It is object based library to create GUI. RTS Tech 5
  • 6. How to get tkinter module  If not installed in python package then we can install it using pip command.  pip install tkinter.  We can import tkinter module.  from tkinter import *  Or  import tkinter RTS Tech 6
  • 7. GUI widgets  Label  Entry  Button  Frame  Menu  Message  Radio button  checkbox RTS Tech 7
  • 8. GUI widgets RTS Tech 8 Label Frame Entry Button
  • 9. Create First GUI  Import tkinter module  Create main window using Tk.  Add widgets like buttons, Labels, Entry etc.  Call main event loop. RTS Tech 9
  • 10. Create A Window  from tkinter import *  window = Tk()  Label(window,text="Hello world“).pack()  window.title(“First Frame")  window.mainloop() RTS Tech 10
  • 11. Label widgets  This is used to show text on the window.  from tkinter import *  main=Tk()  label =Label(  text="Hello, World",  fg="white", # Set the text color to white  bg="black" , # Set the background color to black  font="bold", # Set the font  width=10,#set the width  height=3,#set the height  ).pack()  main.mainloop() RTS Tech 11
  • 12. Button  Button is a label that we can click.  from tkinter import *  main=Tk()  button=Button(  text="Hello, World",  fg="white", # Set the text color to white  bg="black" , # Set the background color to black  font="bold", # Set the font  width=10,#set the width  height=3,#set the height  ).pack()  main.mainloop() RTS Tech 12
  • 13. Get User input  We can take user input using entry widgets.  entry=Entry(  fg="black", # Set the text color to white  bg="Red" , # Set the background color to black  font="bold",  width=100,#set the width  ).pack() RTS Tech 13
  • 14. Entry widgets Operation  entry.get()  To get user input  entry.delete()  To delete specific values of complete data  entry.insert()  To insert values. RTS Tech 14
  • 15. Entry Operations  entry=Entry(  fg="black", # Set the text color to white  bg="Red" , # Set the background color to black  font="bold",  width=100,#set the width  )  entry.insert(0,"Python")  name=entry.get()  print(name)  entry.delete(0)  entry.pack()  RTS Tech 15
  • 16. Text Widgets  from tkinter import *  main=Tk()  text=Text(main).pack()  main.mainloop()  Text widgets are used to get multiline inputs  Text widgets has same methods as entry widgets. RTS Tech 16
  • 17. Text Operations  Text.insert(index,string)  Text.delete(start_index,end_index)  Text.get(strat_index, end _index) RTS Tech 17
  • 18. Get data from text widgets  Text widgets contains multiline input, so we can not just pass a single index like Entry widgets.  We have to pass 2 arguments.  Line no: starts with 1.  Character index: starts with 0.  Index is passed as the string as “<lineNo>.<index>”.  To get 1st charcter of the 1st line  Print(text.get("1.0")).  To get all the data  Print(text.get("1.0“,tkinter.END)). RTS Tech 18
  • 19. Frame Widgets  It is a top level widget which contains other widgets.  It is used to organize the layout of the widgets.  It is used for the logical grouping of other widgets. RTS Tech 19
  • 20. Frame(cont.)  from tkinter import *  from tkinter import font  window =Tk()  frame1=Frame(window,width=100,height=50)  frame2=Frame(window,width=100,height=50)  label1=Label(frame1,bg="maroon",fg="white",text="Frame1”)  label2=Label(frame2,bg="blue",fg="aqua",text="Frame2")  label1.pack()  label2.pack()  frame1.pack()  frame2.pack()  window.mainloop() RTS Tech 20
  • 21. Create frame border  We can create Frame border using relief attribute .  The value for the relief attribute  FLAT  RIDGE  SOLID  GROOVE  SUNKEN  RAISED RTS Tech 21
  • 22. Frame types  frame1=Frame(window,relief=FLAT,borderwidth=5)  lb1=Label(frame1,text="Flat")  frame2=Frame(window,relief=RIDGE,borderwidth=5)  lb2=Label(frame2,text="Ridge")  frame3=Frame(window,relief=SUNKEN,borderwidth=5)  lb3=Label(frame3,text="sunken") RTS Tech 22
  • 23. Layout Management  We can arrange the widgets in different layout.  pack  grid  place RTS Tech 23
  • 24. Pack layout  from tkinter import *  window=Tk()  b1=Button(window,text="Button 1",bg="red")  b2=Button(window,text="Button 2",bg="Green")  b3=Button(window,text="Button 3",bg="yellow")  b4=Button(window,text="Button 4",bg="Orange")  #layout  b1.pack(side="top",fill=X)  b2.pack(side="left",fill=Y)  b3.pack(side="right",fill=Y)  b4.pack(side="bottom",fill=X)  window.mainloop() RTS Tech 24
  • 25. Place Layout  from tkinter import *  window=Tk()  window.geometry("400x200")  lb1=Label(window,text="Enter your name",font=30)  e1=Entry(window)  lb2=Label(window,text="Enter Password",font=30)  e2=Entry(window)  b1=Button(window,text="submit",font=30)  lb1.place(x=20,y=20,height=20,width=150)  lb2.place(x=20,y=50,height=20,width=150)  e1.place(x=190,y=20,width=150)  e2.place(x=190,y=50,width=150)  b1.place(x=50,y=90,height=50,width=150)  window.mainloop() RTS Tech 25
  • 26. Grid Layout  from tkinter import *  window=Tk()  b1=Button(window,text="Button 1",bg="orange")  b2=Button(window,text="Button 2",height=5,width=10,bg="yellow")  b3=Button(window,text="Button 3",height=10,width=15,bg="red")  b1.grid(row=0,column=0,ipadx=5,ipady=3)  b2.grid(row=1,column=0,rowspan=2,ipadx=5,ipady=3)  b3.grid(row=0,column=1,columnspan=2,rowspan=3,ipadx=5,ip ady=3)  window.mainloop() RTS Tech 26
  • 28. Event Listeners Events Description <Button> A mouse button is pressed with the mouse pointer over the widget <FocusIn> Keyboard focus was moved to this widget, <FocusOut> Keyboard focus was moved from this widget to another widget <Motion> The mouse is moved with a mouse button being held down. <Double Button> Similar to the Button event, see above, but the button is double clicked instead of a single click. <key> Any key is pressed RTS Tech 28
  • 29. bind() function  Bind function is used to bind the event to the mainloop  Bind takes 2 arguments  An Event type  An event handler Callback function name  For ex.  window.bind("<Button>",hello) RTS Tech 29
  • 30. Button Click Event  from tkinter import *  window =Tk()  def hello(event):  Label(window,text="Hello ").pack()  btn=Button(window,text="Click Me",font=40,bg="Red",fg='White')  # btn1=Button(window,text="Click Me",font=40,bg="Red",fg='White',command=hello)  btn.pack()  window.bind("<Button>",hello)  window.mainloop() RTS Tech 30
  • 31. Mouse Motion Handler  from tkinter import *  window=Tk()  def getPixel(event):  s="x={} y={}".format(event.x, event.y)  print(s)  text="""This is a simple example of a  event Handling in Tkinter.  we are learning about Motion event.  """  msg=Message(window,text=text,bg="aqua",font=30)  msg.pack(side="left")  img=PhotoImage("indore.png",format="png")  l1=Label(window,image=img)  l1.pack(side="right")  window.bind("<Motion>",getPixel)  window.mainloop() RTS Tech 31
  • 32. An application(calculator)  from tkinter import *  window=Tk()  window.title("Calculator")  window.geometry("500x500")  #input variables  n1=StringVar()  n2=StringVar()  n3=StringVar()  #callback functoin  def add():  a=int(n1.get())  b=int(n2.get())  n3.set("{}".format(a+b))  def clr():  n1.set("")  n2.set("")  n3.set("") RTS Tech 32
  • 33. Calculator(cont.)  #create widgets  l1=Label(window,text="Enter 1st Number",font=("Times",30))  l2=Label(window,text="Enter 2nd Number",font=("Times",30))  l3=Label(window,text="Result",font=("Times",30))  e1=Entry(window,textvariable=n1)  e2=Entry(window,textvariable=n2)  e3=Entry(window,textvariable=n3,readonlybackground="aqua")  b1=Button(window,text="Add",font=("Times",30),command=add)  b2=Button(window,text="ClearText",font=("Times",30),command =clr) RTS Tech 33
  • 34. Calculator(cont.)  #manage layout  l1.grid(row=0,column=0)  l2.grid(row=1,column=0)  l3.grid(row=2,column=0)  e1.grid(row=0,column=1)  e2.grid(row=1,column=1)  e3.grid(row=2,column=1)  b1.grid(row=3,column=0)  b2.grid(row=3,column=1)  window.mainloop()  RTS Tech 34
  • 35. Disclaimer  This is a educational Presentation to make programming easier.  We have used images of different URLs to make presentation better.  We respect the work of the owners of the URLs.
  • 37. Disclaimer  This is an educational presentation to enhance the skill of computer science students.  This presentation is available for free to computer science students.  Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world.  We are grateful to owners of these URLs and pictures. RTS Tech 37

Editor's Notes

  • #2: www.sunilos.com
  • #11: www.sunilos.com
  • #24: www.sunilos.com