This content originally appeared on DEV Community and was authored by Mate Technologies
π 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
This content originally appeared on DEV Community and was authored by Mate Technologies
Mate Technologies | Sciencx (2026-04-05T05:37:00+00:00) π Build a Professional Image Converter GUI in Python (Step-by-Step). Retrieved from https://www.scien.cx/2026/04/05/%f0%9f%9a%80-build-a-professional-image-converter-gui-in-python-step-by-step/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
