Python - Gui Programming (Tkinter)

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 33

PYTHON - GUI PROGRAMMING (TKINTER)

GEOMETRY MANAGEMENT
All Tkinter widgets have access to specific geometry management
methods, which have the purpose of organizing widgets
throughout the parent widget area. Tkinter exposes the following
geometry manager classes: pack, grid, and place.
 The pack() Method − This geometry manager organizes widgets
in blocks before placing them in the parent widget.
 The grid() Method − This geometry manager organizes widgets
in a table-like structure in the parent widget.
 The place() Method − This geometry manager organizes widgets
by placing them in a specific position in the parent widget.
PACK() METHOD
GRID() METHOD
PLACE() METHOD
PYTHON - GUI PROGRAMMING (TKINTER)
GUI PROGRAMMING
Python provides various options for developing graphical user interfaces
(GUIs). Most important are listed below.

 Tkinter − Tkinter is the Python interface to the Tk GUI toolkit shipped with
Python.
 wxPython − This is an open-source Python interface for wxWindows
http://wxpython.org.
 JPython − JPython is a Python port for Java which gives Python scripts
seamless access to Java class libraries on the local machine
http://www.jython.org
TKINTER PROGRAMMING
 Tkinter is the standard GUI library for Python. Python
when combined with Tkinter provides a fast and easy
way to create GUI applications. Tkinter provides a
powerful object-oriented interface to the Tk GUI toolkit.
TKINTER PROGRAMMING
 Creating a GUI application using Tkinter is an easy task.

All you need to do is perform the following steps −


 Import the Tkinter module.
 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 the user.
TKINTER PROGRAMMING
import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
TKINTER WIDGETS
Tkinter provides various controls, such as buttons, labels
and text boxes used in a GUI application. These controls
are commonly called widgets.

There are currently 15 types of widgets in Tkinter. We


present these widgets as well as a brief description in the
following table −
TKINTER WIDGETS
TKINTER WIDGETS
TKINTER WIDGETS
TKINTER WIDGETS
STANDARD ATTRIBUTES
 Let us take a look at how some of their common attributes.such
as sizes, colors and fonts are specified.
• Dimensions
• Colors
• Fonts
• Anchors
• Relief styles
• Bitmaps
• Cursors
GEOMETRY MANAGEMENT
All Tkinter widgets have access to specific geometry management
methods, which have the purpose of organizing widgets
throughout the parent widget area. Tkinter exposes the following
geometry manager classes: pack, grid, and place.
 The pack() Method − This geometry manager organizes widgets
in blocks before placing them in the parent widget.
 The grid() Method − This geometry manager organizes widgets
in a table-like structure in the parent widget.
 The place() Method − This geometry manager organizes widgets
by placing them in a specific position in the parent widget.
TKMESSAGEBOX
TKMESSAGEBOX
SQL USING PYTHON
SQLITE3
Databases offer numerous functionalities by which one can manage large
amounts of information easily over the web, and high-volume data input and
output over a typical file such as a text file. SQL is a query language and is very
popular in databases. Many websites use MySQL. SQLite is a “light” version
that works over syntax very much similar to SQL.
SQLite is a self-contained, high-reliability, embedded, full-featured, public-
domain, SQL database engine. It is the most used database engine in the world
wide web.
Python has a library to access SQLite databases, called sqlite3, intended for
working with this database which has been included with Python package since
version 2.5.
SQL USING PYTHON

 We will discuss all the CRUD operations on the SQLite3 database


using Python. CRUD contains four major operations.
 C - Create
 R - Read
 U - Update
 D - Delete
CONNECTING TO SQLITE3

 To use SQLite, we must import sqlite3

 Then create a connection using connect() method and pass the


name of the database you want to access if there is a file with that
name, it will open that file. Otherwise, Python will create a file
with the given name.
CONNECTING TO SQLITE3

 Then create a cursor object. It is called to send commands to the


SQL

 To close the database connection we will use the following


commands.
CURSOR OBJECT

Before moving further to SQLite3 and Python let’s discuss the cursor
object in brief.
 The cursor object is used to make the connection for executing SQL
queries.
 It acts as middleware between SQLite database connection and SQL
query. It is created after giving connection to SQLite database.
 The cursor is a control structure used to traverse and fetch the
records of the database.
 All the commands will be executed using cursor object only.
EXECUTING SQLITE3 QUERIES – CREATING
TABLES
 After connecting to the database and creating the cursor object let’s see how to
execute the queries.
 To execute a query in the database, create an object and write the SQL command
in it with being commented. Example:- sql_comm = ”SQL statement”
 And executing the command is very easy. Call the cursor method execute() and
pass the name of the sql command as a parameter in it. Save a number of
commands as the sql_comm and execute them. After you perform all your
activities, save the changes in the file by committing those changes and then lose
the connection.
EXECUTING SQLITE3 QUERIES – CREATING
TABLES
INSERTING DATA INTO TABLE

 To insert data into the table


we will again write the SQL
command as a string and will
use the execute() method.
FETCHING DATA

 Fetching the data from


records is simple as inserting
them. The execute method
uses the SQL command of
getting all the data from the
table using “Select * from
table_name” and all the table
data can be fetched in an
object in the form of a list of
lists.
FETCHING DATA
UPDATING DATA

 For updating the data in the SQLite3 table we will use the UPDATE statement. We can update
single columns as well as multiple columns using the UPDATE statement as per our
requirement.
DELETING DATA

 DROP is used to delete the entire database or a table. It deleted both records in the table along
with the table structure.
DELETING TABLE

 DROP is used to delete the entire database or a table. It deleted both records in the table along
with the table structure.

You might also like