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)