๐ Full source code:
https://github.com/rogers-cyber/python-tiny-tools/blob/main/63-Image-resizer/ImageConvertPRO.py
๐ง What Youโll Build
In this tutorial, weโll create a modern desktop app that can:
๐ Add images (files, folders, drag & drop)
๐ผ Preview thumbnails
๐ Convert formats (PNG, JPEG, WEBP, etc.)
๐ Resize images
๐พ Save conversion history (SQLite)
โก Run conversions in background (no freezing UI)
๐ฆ Step 1: Install Dependencies
pip install pillow ttkbootstrap tkinterdnd2
๐ Why we need them:
Pillow โ image processing
ttkbootstrap โ modern UI styling
tkinterdnd2 โ drag & drop support
๐ Step 2: Project Setup
Create a Python file:
image_convert_pro.py
โ๏ธ Step 3: Import Libraries
import os
import sys
import sqlite3
from threading import Thread
from PIL import Image, ImageTk
๐ง Explanation:
os, sys โ file handling
sqlite3 โ local database
Thread โ run tasks without freezing UI
PIL โ image processing
Handle Image Resampling (Important!)
try:
from PIL import ImageResampling
RESAMPLE = ImageResampling.LANCZOS
except:
RESAMPLE = Image.LANCZOS
โ This ensures compatibility across Pillow versions.
๐จ Step 4: Import UI Libraries
import ttkbootstrap as tb
from ttkbootstrap.constants import *
from tkinter import filedialog, messagebox, Listbox, Canvas, Scrollbar
from tkinterdnd2 import TkinterDnD, DND_FILES
๐ท Step 5: App Configuration
APP_NAME = "ImageConvert PRO"
APP_VERSION = "1.1"
๐ Step 6: Setup Paths
BASE_DIR = os.path.dirname(sys.argv[0])
DB_NAME = os.path.join(BASE_DIR, "snapconvert.db")
OUTPUT_DIR = os.path.join(BASE_DIR, "converted")
๐ Step 7: Create Database
Create table
def init_db():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS history(
id INTEGER PRIMARY KEY,
name TEXT,
original TEXT,
converted TEXT)""")
conn.commit()
conn.close()
Insert data
def insert_db(name, orig, conv):
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute("INSERT INTO history(name, original, converted) VALUES(?,?,?)",(name,orig,conv))
conn.commit()
conn.close()
Fetch history
def fetch_db():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute("SELECT name, original, converted FROM history ORDER BY id DESC")
rows = c.fetchall()
conn.close()
return rows
Clear history
def clear_history():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute("DELETE FROM history")
conn.commit()
conn.close()
โน๏ธ Step 8: About Dialog
def show_about():
messagebox.showinfo(
f"About {APP_NAME}",
f"{APP_NAME} v{APP_VERSION}\n\n"
"Professional Image Converter\n\n"
"ยฉ 2026 Mate Technologies\n"
"https://matetools.gumroad.com"
)
โก Step 9: Image Processing Worker (Core Logic)
def worker(images, fmt, out, quality, resize, keep, progress, finish):
os.makedirs(out, exist_ok=True)
๐ Loop through images
for i, path in enumerate(images):
try:
with Image.open(path) as img:
Resize (optional)
if resize > 0:
img = img.resize((resize, resize), RESAMPLE)
Convert format safely
if fmt == "JPEG" and img.mode in ("RGBA","P"):
img = img.convert("RGB")
Save file
img.save(out_path, fmt)
Update progress
progress(int((i+1)/total*100))
Finish callback
finish(count)
๐ฅ Step 10: Build Main App Class
class App:
def __init__(self):
self.root = TkinterDnD.Tk()
self.root.title(APP_NAME)
self.root.geometry("1200x750")
๐ Step 11: Menu Bar
def create_menu(self):
menubar = tb.Menu(self.root)
help_menu = tb.Menu(menubar, tearoff=0)
help_menu.add_command(label="About", command=show_about)
menubar.add_cascade(label="Help", menu=help_menu)
self.root.config(menu=menubar)
๐งฉ Step 12: Build UI Layout
We divide into 3 sections:
LEFT โ File list
self.listbox = Listbox(left, bg="#1e1e1e", fg="white")
Buttons:
Add Images
Add Folder
Remove
Clear
CENTER โ Image preview
self.canvas = Canvas(center, bg="#121212")
โ Scrollable gallery
RIGHT โ Settings panel
self.format = tb.Combobox(right, values=["PNG","JPEG","WEBP","BMP","TIFF"])
Options:
Format
Quality
Resize
Keep filename
Convert button
tb.Button(right, text="๐ Convert", command=self.convert)
๐ฑ Step 13: Drag & Drop Support
self.root.drop_target_register(DND_FILES)
self.root.dnd_bind("<<Drop>>", self.drop)
๐ผ Step 14: Render Image Gallery
def render_gallery(self):
for i, path in enumerate(self.images[:50]):
img = Image.open(path)
img.thumbnail((150,150))
โ Displays thumbnails in grid layout
๐ Step 15: Convert Images (Threaded)
def convert(self):
Thread(target=worker, args=(...), daemon=True).start()
๐ง Why threading?
Without it:
โ UI freezes
With it:
โ
Smooth experience
๐ Step 16: Progress Bar
self.progress = tb.Progressbar(right)
Update:
self.progress.config(value=v)
๐ Step 17: Delete History
def delete_history(self):
if messagebox.askyesno("Confirm", "Delete all history?"):
clear_history()
โถ๏ธ Step 18: Run the App
if __name__ == "__main__":
init_db()
App().run()
๐ Final Result
You now have a fully functional desktop app with:
โ
Modern UI
โ
Drag & drop
โ
Image conversion
โ
Resize + quality control
โ
History tracking
โ
Multithreading
๐ก Bonus Ideas (for improvement)
๐ Add search in history
๐ Light/Dark mode toggle
๐ฆ Export history to CSV
โก Batch rename rules
๐ง AI auto image optimization

Top comments (0)