Python Integration Primer – Detailed Notes
3.1 Graphical User Interface (GUI) and Database Connectivity in Python
---------------------------------------------------------------------
A. GUI Frameworks
1. Tkinter
- Built-in Python GUI toolkit.
- Provides widgets such as Button, Label, Entry, Text, Frame, Canvas.
- Event-driven: functions are triggered using commands or bindings.
- Supports geometry managers like pack(), grid(), place().
2. PyQt
- A feature-rich framework for professional GUI apps.
- Designer tool allows drag■and■drop UI creation.
- Supports signals and slots for event handling.
- Contains advanced widgets like TreeView, TableView, Tabs, Splitter.
B. Widgets Overview
- Button: triggers actions.
- Label: displays text/images.
- Entry: single-line user input.
- Text: multi-line input.
- Checkbutton: boolean options.
- Radiobutton: mutually exclusive options.
- Scrollbar: provides scrolling for text/canvas.
- Canvas: drawing shapes, displaying images.
C. Working with Containers
- Frame: organizes widgets into sections.
- Canvas: used for graphics, diagramming, and image display.
D. Database Connectivity
- SQLite:
• Lightweight, file■based database.
• Uses Python's sqlite3 module.
- MySQL:
• Requires mysql-connector or PyMySQL.
E. CRUD Operations from GUI
- Create: insert records using INSERT.
- Read: display records in labels, listboxes, tables.
- Update: modify entries via UPDATE query.
- Delete: remove records using DELETE.
Example (Tkinter + SQLite):
-----------------------------------------------------
import sqlite3
conn = [Link]("[Link]")
cur = [Link]()
[Link]("INSERT INTO users(name, age) VALUES(?,?)", ("John", 22))
[Link]()
3.2 GUI Basic Image Processing using OpenCV
-------------------------------------------
A. OpenCV Basics
- Load images: [Link]()
- Display images: [Link]()
- Resize: [Link]()
- Rotate: [Link]()
- Convert color space: [Link]()
B. Integrating Image Processing with GUI
- Tkinter can display OpenCV images by converting them to PhotoImage.
- PyQt supports QLabel for displaying processed images.
C. Typical Image Operations
- Blurring: [Link]()
- Edge Detection: [Link]()
- Thresholding: [Link]()
Example:
-----------------------------------------------------
img = [Link]("[Link]")
gray = [Link](img, cv2.COLOR_BGR2GRAY)
blur = [Link](gray, (5,5), 0)
3.3 Django Web Application Framework
------------------------------------
A. Architecture
- MTV pattern (Model–Template–View)
• Model: data layer (ORM).
• Template: HTML rendering.
• View: handles logic and requests.
B. Features
- URL routing system.
- Built-in authentication.
- Admin interface.
- Form handling.
- ORM for database interactions.
C. Example Django Model
-----------------------------------------------------
class Student([Link]):
name = [Link](max_length=100)
age = [Link]()
D. Example View
-----------------------------------------------------
def home(request):
return render(request, "[Link]")
E. Example Template
-----------------------------------------------------
Welcome to Django App