SlideShare a Scribd company logo
1 of 37
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

More Related Content

What's hot (20)

Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python list
Python listPython list
Python list
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
 
Python
PythonPython
Python
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
Python basic
Python basicPython basic
Python basic
 
Python ppt
Python pptPython ppt
Python ppt
 
Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
 
List in Python
List in PythonList in Python
List in Python
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 

Similar to Python GUI Programming

Tkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfTkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfArielManzano3
 
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.pdfFootageetoffe16
 
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 88Mahmoud 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 - PROJECTMahmutKAMALAK
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxMohamed Essam
 
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationCodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationLee 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
 
tkinter final ppt.ppt
tkinter final ppt.ppttkinter final ppt.ppt
tkinter final ppt.pptKanuAgrawal2
 
wcmc_practicals
wcmc_practicalswcmc_practicals
wcmc_practicalsMannMehta7
 
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 tkinterMohamed Essam
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...Yashpatel821746
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
Hack2the future Microsoft .NET Gadgeteer
Hack2the future Microsoft .NET GadgeteerHack2the future Microsoft .NET Gadgeteer
Hack2the future Microsoft .NET GadgeteerLee Stott
 

Similar to Python GUI Programming (20)

Tkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdfTkinter_GUI_Programming_in_Python.pdf
Tkinter_GUI_Programming_in_Python.pdf
 
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
 
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
 
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
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptx
 
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer PresentationCodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
CodePool Liverpool 2013 - Microsoft Gadgeteer Presentation
 
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)
 
tkinter final ppt.ppt
tkinter final ppt.ppttkinter final ppt.ppt
tkinter final ppt.ppt
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Chapter - 6.pptx
Chapter - 6.pptxChapter - 6.pptx
Chapter - 6.pptx
 
wcmc_practicals
wcmc_practicalswcmc_practicals
wcmc_practicals
 
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
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
Hack2the future Microsoft .NET Gadgeteer
Hack2the future Microsoft .NET GadgeteerHack2the future Microsoft .NET Gadgeteer
Hack2the future Microsoft .NET Gadgeteer
 
Java Programming Projects
Java Programming ProjectsJava Programming Projects
Java Programming Projects
 

Recently uploaded

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 

Recently uploaded (20)

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 

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

  1. www.sunilos.com
  2. www.sunilos.com
  3. www.sunilos.com