DEV Community

Mate Technologies
Mate Technologies

Posted on

🚀 Build a Professional Image Converter GUI in Python (Step-by-Step)

👉 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
Enter fullscreen mode Exit fullscreen mode

🧠 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
Enter fullscreen mode Exit fullscreen mode

✔ 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
Enter fullscreen mode Exit fullscreen mode

🏷 Step 5: App Configuration

APP_NAME = "ImageConvert PRO"
Enter fullscreen mode Exit fullscreen mode

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")
Enter fullscreen mode Exit fullscreen mode

🗄 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()
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Clear history

def clear_history():
    conn = sqlite3.connect(DB_NAME)
    c = conn.cursor()
    c.execute("DELETE FROM history")
    conn.commit()
    conn.close()
Enter fullscreen mode Exit fullscreen mode

ℹ️ 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"
    )
Enter fullscreen mode Exit fullscreen mode

⚡ 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))
Enter fullscreen mode Exit fullscreen mode

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")
Enter fullscreen mode Exit fullscreen mode

📋 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)
Enter fullscreen mode Exit fullscreen mode

🧩 Step 12: Build UI Layout

We divide into 3 sections:

LEFT → File list

self.listbox = Listbox(left, bg="#1e1e1e", fg="white")
Enter fullscreen mode Exit fullscreen mode

Buttons:

Add Images

Add Folder

Remove

Clear

CENTER → Image preview

self.canvas = Canvas(center, bg="#121212")
Enter fullscreen mode Exit fullscreen mode

✔ Scrollable gallery

RIGHT → Settings panel

self.format = tb.Combobox(right, values=["PNG","JPEG","WEBP","BMP","TIFF"])
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

🖼 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))
Enter fullscreen mode Exit fullscreen mode

✔ Displays thumbnails in grid layout

🔄 Step 15: Convert Images (Threaded)

def convert(self):
    Thread(target=worker, args=(...), daemon=True).start()
Enter fullscreen mode Exit fullscreen mode

🧠 Why threading?

Without it:
❌ UI freezes
With it:
✅ Smooth experience

📊 Step 16: Progress Bar

self.progress = tb.Progressbar(right)
Enter fullscreen mode Exit fullscreen mode

Update:

self.progress.config(value=v)
Enter fullscreen mode Exit fullscreen mode

🗑 Step 17: Delete History

def delete_history(self):
    if messagebox.askyesno("Confirm", "Delete all history?"):
        clear_history()
Enter fullscreen mode Exit fullscreen mode

▶️ Step 18: Run the App

if __name__ == "__main__":
    init_db()
    App().run()
Enter fullscreen mode Exit fullscreen mode

🎉 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)