Development of Graphical User Interface (GUI)Development of Graphical User Interface (GUI)
Building Tkinter desktop interfaces (windows, frames, widgets, pack/grid/place, event-driven login form) and persisting data via sqlite3/MySQL with relational concepts, SQL and CRUD operations.
Designing Clean and Responsive Interfaces · Reviewed lesson · version 1 · published 16 Nov 2026
A clean interface has well-arranged widgets and enough space between them. Text and buttons should be clear and easy to read. Responsive interfaces adjust their layout when the window size changes. This helps the program work well on different screen sizes. Proper alignment improves the overall look of the application. Simple design makes the interface user-friendly.
Tkinter Components and Widgets · Reviewed lesson · version 1 · published 16 Nov 2026
Tkinter provides many components, called widgets, that help build interactive graphical applications. A program can contain multiple visual elements such as windows, frames, buttons, and text fields. These widgets allow users to enter data, choose options, or perform actions. Each widget has its own purpose, and combining them creates a complete interface. Tkinter also supports layout management, so widgets can be arranged neatly on the screen.
What is a GUI? Why is it important? · Reviewed lesson · version 1 · published 16 Nov 2026
A GUI, or Graphical User Interface, is a visual interface that allows users to interact with software using elements like buttons, menus, and forms. GUIs are important because they make programs easier to understand and operate, especially for non-technical users. They improve usability by providing visual feedback and reducing the need to remember complex commands. GUI applications are widely used in desktop software, web applications, and mobile apps.
Executing SQL Commands From Python · Reviewed lesson · version 1 · published 16 Nov 2026
SQL commands are used to interact with the database from Python. Python sends these commands using a database cursor. Commands can be used to create tables or insert data. Data can also be retrieved using select queries. Executing SQL commands allows Python programs to manage database data effectively.
Introduction · Reviewed lesson · version 1 · published 16 Nov 2026
In this chapter, students will learn to develop user-friendly Graphical User Interfaces (GUIs) using Tkinter, Python's built-in GUI toolkit. They will create windows, frames, labels, buttons, entry fields, and manage layouts using pack(), grid(), and place(). They will practice event handling by linking user actions with functions and developing a simple login form. The chapter also introduces database concepts, SQL, Python database connectivity, and basic CRUD operations using SQLite or MySQL.
Read: Retrieving and Displaying Data · Reviewed lesson · version 1 · published 16 Nov 2026
The Read operation is used to fetch data from the database. It helps display stored records when needed. SQL select commands are commonly used for reading data. Python retrieves the results and processes them. This operation does not change the stored data.
Overview of Relational Databases and SQL Structure
Overview of Relational Databases and SQL Structure · Reviewed lesson · version 1 · published 16 Nov 2026
Relational databases organize data into tables made of rows and columns. Each table stores related data in a structured manner. Relationships between tables are maintained using keys. SQL stands for Structured Query Language and is used to interact with databases. SQL commands help create, read, update, and delete data.
Introduction to Databases · Reviewed lesson · version 1 · published 16 Nov 2026
A database is an organized collection of data stored in a structured format. It allows data to be accessed and managed easily. Databases reduce data duplication and improve reliability. They support secure storage of information. Databases are commonly used in many types of software applications.
Entity: An entity is a real-world object, person, place, event, or concept about which data is stored in a database.
Example: Student, Teacher, Course, Book, Employee
Attribute: An attribute is a property or characteristic of an entity. It describes specific information about an entity.
Example: For the entity Student, attributes can be:
Student Name
Roll Number
Class
Age
Relationship: A relationship shows how two or more entities are connected with each other.
Example: A Student enrols in a Course. Here, enrols in is the relationship between Student and Course.
Identifier: An identifier is an attribute that uniquely identifies each record or object of an entity.
Example: For the entity Student, Roll Number can be used as an identifier because each student has a unique roll number.
Layout Management
Layout Management · Reviewed lesson · version 1 · published 16 Nov 2026
Layout management is used to arrange widgets inside a window in a proper way. It decides the position and size of each widget on the screen. Good layout management makes the interface clear and easy to use. It also helps in keeping the window organized. Tkinter provides different methods to manage layout. Each method has its own way of placing widgets.
Event Handling and Interactivity · Reviewed lesson · version 1 · published 16 Nov 2026
Event handling and interactivity allow a program to respond to user actions. An event is an action, such as clicking a button or typing text. The program waits for an event instead of running all the time. When an event occurs, a specific task is performed. This makes the application active and useful. Event handling is important in graphical programs. It helps control how the program behaves.
4.2 Working with Databases in Python · Reviewed lesson · version 1 · published 16 Nov 2026
Working with databases in Python involves storing and managing data using database systems. Python programs can connect to databases to insert, retrieve, update, and delete data. Databases allow applications to handle large amounts of information efficiently. Using databases helps maintain data accuracy and consistency. Python supports database operations through built-in and external libraries.
Understanding Databases · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 0.1 MB
Databases store important data required for application operation. They allow applications to manage large data sets effectively. Key database concepts are:
Relational Database: A database that stores data in tables (rows and columns) and links them using relationships.
Table: A collection of related data organised in rows (records) and columns (fields). (as shown in Figure 4.3).
Column: A property or characteristic of an entity (e.g., name, age).
Primary Key: A unique identifier for each record in a table.
Foreign Key: A field that links one table to another by referring to the primary key of another table.
Figure 4.3: Tables, Columns, Records, Fields, Primary Key, and Foreign Key Relationship (original drawing after the textbook's Figure 4.3).
Handling User Input and Connecting Widgets to Functions
Handling User Input and Connecting Widgets to Functions · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 67 KB
User input is given through widgets like entry fields and buttons. Widgets are connected to functions in the program. When the widget is used, the connected function executes. This allows the program to process the input. For example, a button click can display a message. Proper connections ensure correct program behavior. This interaction improves user experience.
Example: Simple Login Form
A simple login form allows a user to enter a username and password. Entry fields are used to take the input from the user. A button is provided to submit the information. When the button is clicked, the program checks the entered data. A message is then shown for success or error.
Example:
python
importtkinterastkfromtkinterimportmessagebox# Create main window
Using sqlite3 or MySQL to Establish a Database Connection
Using sqlite3 or MySQL to Establish a Database Connection · Reviewed lesson · version 1 · published 16 Nov 2026
The sqlite3 library is built into Python and is used for small databases. It stores data in a single file on the system. MySQL is used for larger and more complex database systems. A connection is created by providing database details such as name and credentials. A successful connection allows Python to access the database.
python
# Import sqlite3 moduleimportsqlite3# Connect to the database file named "school.db"# If the file does not exist, SQLite will create it automaticallyconnection = sqlite3.connect("school.db")
# Create a cursor object# Cursor is used to execute SQL queriescursor = connection.cursor()
# Create "students" table if it does not existcursor.execute(""" CREATE TABLE IF NOT EXISTS students
( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, grade TEXT ) """
Creating Windows and Adding Frames
Creating Windows and Adding Frames · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 36 KB
A Tkinter program begins by creating a main window, which serves as the base for all other elements. The window can be resized, given a title, and designed to hold different widgets. Frames are sections within the window that help organize content. Frames divide the window into smaller parts, making it easier to group related widgets. This structure improves clarity and keeps the interface well-arranged.
Example:
python
importtkinterastk# Create main windowwindow = tk.Tk()
window.title("Tkinter Frames Example")
window.geometry("400x300")
# Create top frametop_frame =
Understanding Event-Driven Programming
Understanding Event-Driven Programming · Reviewed lesson · version 1 · published 16 Nov 2026
Event-driven programming is based on actions called events. The program remains idle until an event occurs. Common events include button clicks and key presses. Each event is linked to a specific function. The function runs only when the event happens. This approach saves system resources. It is widely used in graphical user interfaces.
Create: Adding New Records · Reviewed lesson · version 1 · published 16 Nov 2026
The Create operation is used to add new data to a database table. It stores information such as names, values, or records. SQL insert commands are used for this purpose. Python sends these commands to the database. New records become part of the stored data after execution.
Common Widgets: Labels, Buttons, Entry Fields, Menus, and List boxes
Common Widgets: Labels, Buttons, Entry Fields, Menus, and List boxes · Reviewed lesson · version 1 · published 16 Nov 2026
Widgets are the basic elements used to build a graphical user interface. A Label is used to display text or messages on the screen. A Button allows the user to perform an action when it is clicked. An Entry field is used to enter text, such as a name or password. A Menu provides a list of options at the top of the window. A Listbox shows a list of items and allows selection from the list.
Summary · Reviewed lesson · version 1 · published 16 Nov 2026
Graphical User Interface
A Graphical User Interface (GUI) is a visual way of interacting with a computer program using windows, buttons, menus, text boxes, and other graphical elements.
Tkinter
Tkinter is Python's built-in library used to create desktop-based graphical user interfaces.
Window
A window is the main screen or container in a GUI application where different interface elements are displayed.
Frame
A frame is a container used to organize and group widgets inside a GUI window.
Widget
A widget is a GUI element, such as a label, button, entry field, menu, or listbox, used to display information or receive input from the user.
Event-Driven Programming
Event-driven programming is a programming approach in which the program responds to events or actions performed by the user.
Overview of Tkinter as Python's built-in GUI toolkit
Overview of Tkinter as Python's built-in GUI toolkit · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 38 KB
Tkinter is Python's standard GUI toolkit that comes pre-installed with the language. It provides a set of classes and functions to create windows, buttons, labels, entry fields, and other widgets. Tkinter is easy to learn, lightweight, and supports event-driven programming, where actions are triggered by user events. It is suitable for building small to medium-sized GUI applications quickly and efficiently.
Example:
python
importtkinterastk# Create main windowwindow = tk.Tk()
window.title("Simple GUI Example")
window.geometry("300x200")
# Function to handle button click (event)def
Organizing Elements using pack(), grid(), and place()
Organizing Elements using pack(), grid(), and place() · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 0.2 MB
The pack() method places widgets in a simple vertical or horizontal order. It is easy to use and works well for small applications. The grid() method arranges widgets in rows and columns like a table. It is useful for forms and structured layouts. The place() method positions widgets at exact locations on the window (as shown in Figure 4.2). It gives more control but needs careful adjustment.
Figure 4.2: Diagram showing Tkinter Layout Managers: pack(), grid(), place() (original drawing after the textbook's Figure 4.2).
Example pack():
python
importtkinterastk# Create main windowwindow = tk
4.1 Graphical User Interface (GUI) Development with Tkinter
4.1 Graphical User Interface (GUI) Development with Tkinter · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 36 KB
Graphical User Interface (GUI) development allows programs to interact with users through visual elements like windows, buttons, labels, and text boxes (as shown in Figure 4.1). GUIs make applications more user-friendly and easier to use compared to command-line interfaces. Python provides tools to create GUI applications efficiently. Tkinter is Python's built-in library for creating GUI programs. It is simple, widely used, and allows developers to design interactive applications quickly.
Figure 4.1: Graphical User Interface (GUI) (original drawing after the textbook's Figure 4.1).
Update: Modifying Existing Records · Reviewed lesson · version 1 · published 16 Nov 2026
The Update operation changes existing data in a database. It is used when stored information needs correction. SQL update commands modify selected records. Python executes these commands based on conditions. Only the specified data is changed during this process.
Delete: Removing Data Safely · Reviewed lesson · version 1 · published 16 Nov 2026
The Delete operation removes unwanted data from a database. It helps keep the database clean and accurate. SQL delete commands are used with conditions. Python ensures only selected records are removed. Careful use prevents loss of important data.
Example:
python
importsqlite3# Connect to the databaseconnection = sqlite3.connect("school.db")
# Create a cursor objectcursor = connection.cursor()
# Execute DELETE query (example: delete student with ID = 1)cursor.execute("DELETE FROM students WHERE ID = 1")
# Save changesconnection.commit()
CRUD Operations
CRUD Operations · Reviewed lesson · version 1 · published 16 Nov 2026
Images and handouts: 0.1 MB
CRUD stands for Create, Read, Update, and Delete and defines basic database actions. These operations are used to manage data stored in a database (as shown in Figure 4.4 and Table 4.1). Every database-based application depends on CRUD operations. They help maintain accurate and up-to-date information. Python uses SQL commands to perform these operations on databases.
Figure 4.4: Diagram showing Create, Read, Update, and Delete operations on a table (original drawing after the textbook's Figure 4.4).
Table 4.1: CRUD operations
Command
Command Example
Description
INSERT
INSERT INTO students (ID, Name, Age) VALUES (1, 'John', 20);
Adds a new record to a table.
Connecting Python to a Database
Connecting Python to a Database · Reviewed lesson · version 1 · published 16 Nov 2026
Connecting Python to a database allows programs to work with stored data. A database connection is required before performing any data operation. Python provides libraries that help establish this connection easily. Once connected, data can be added, retrieved, or modified. Proper connection handling ensures smooth communication between Python and the database.
Output of the login form example: the Login Form window and the Success message box (original drawing after the windows printed beside the textbook's code).