In this tutorial, weโll build AutoValue Pro, a desktop application that predicts used car prices using Machine Learning and a modern Python GUI.
By the end, youโll learn how to:
Use Linear Regression for predictions
Build a desktop GUI with Tkinter + ttkbootstrap
Run ML tasks in a background thread
Display results with a progress bar
๐ Project Source Code (GitHub):
https://github.com/rogers-cyber/python-tiny-tools/tree/main/Car-price-prediction-GUI
๐ง What Weโre Building
AutoValue Pro v1.0
AI-powered used car price predictor
Desktop GUI
Inputs:
Number of owners
Kilometers driven
Manufacturing year
๐ ๏ธ Step 1: Install Required Libraries
Make sure Python 3.9+ is installed, then run:
pip install numpy scikit-learn ttkbootstrap
Why these libraries?
numpy โ numerical operations
scikit-learn โ machine learning model
ttkbootstrap โ modern Tkinter UI styling
๐ Step 2: Import Dependencies
Start by importing all required modules.
import os
import sys
import threading
import tkinter as tk
from tkinter import messagebox
import ttkbootstrap as tb
from ttkbootstrap.constants import *
import numpy as np
from sklearn.linear_model import LinearRegression
Explanation:
threading keeps the UI responsive
tkinter builds the GUI
LinearRegression powers our AI model
๐ฆ Step 3: Handle File Paths (Utility Function)
This helps when packaging the app later (e.g., with PyInstaller).
def resource_path(file_name):
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, file_name)
โ This ensures icons and assets load correctly.
๐ค Step 4: Create the Machine Learning Worker
We separate ML logic from the UI using a worker class.
class PredictionWorker:
def __init__(self, features, callbacks):
self.features = features
self.callbacks = callbacks
self._running = True
Why?
Keeps the GUI smooth
Makes the code cleaner and scalable
๐ Step 4.1: Train a Demo Model
We train a simple Linear Regression model using sample data.
self.model = LinearRegression()
X = np.array([
[1, 5000, 2015],
[2, 3000, 2018],
[3, 2000, 2020],
[1, 8000, 2012],
[2, 4000, 2016]
])
y = np.array([12000, 15000, 18000, 9000, 14000])
self.model.fit(X, y)
๐ Features used:
Number of owners
Kilometers driven
Manufacturing year
โถ๏ธ Step 4.2: Run the Prediction
def run(self):
try:
prediction = self.model.predict([self.features])[0]
if not self._running:
return
if "result" in self.callbacks:
self.callbacks["result"](round(prediction, 2))
except Exception as e:
if "error" in self.callbacks:
self.callbacks["error"](str(e))
โ Predicts price
โ Sends result back to the UI
๐ฅ๏ธ Step 5: Create the Main GUI App
class AutoValueApp:
APP_NAME = "AutoValue Pro"
APP_VERSION = "1.0"
We initialize the main window:
self.root = tb.Window(themename="darkly")
self.root.title("AutoValue Pro v1.0")
self.root.minsize(900, 550)
๐จ darkly gives us a modern dark theme.
๐งพ Step 6: Build the User Interface
Title & Subtitle
tb.Label(
main,
text="๐ AutoValue Pro โ Car Price Predictor",
font=("Segoe UI", 22, "bold")
).pack()
๐งฎ Input Fields
self.owner_var = tk.IntVar(value=1)
self.km_var = tk.IntVar(value=3000)
self.year_var = tk.IntVar(value=2018)
tb.Label(form, text="Number of Owners").grid(row=0, column=0)
tb.Spinbox(form, from_=1, to=5, textvariable=self.owner_var).grid(row=0, column=1)
๐ We repeat this pattern for KM driven and year.
๐ Step 7: Buttons (Predict & Cancel)
self.predict_btn = tb.Button(
btns,
text="๐ฎ Predict Price",
bootstyle=SUCCESS,
command=self.start_prediction
)
self.cancel_btn = tb.Button(
btns,
text="โน Cancel",
bootstyle=DANGER,
state=DISABLED,
command=self.cancel
)
โณ Step 8: Progress Bar Animation
self.progress = tb.Progressbar(
main,
maximum=100,
bootstyle="success-striped"
)
def animate_progress(self):
if self.smooth_value < self.target_progress:
self.smooth_value += 1
self.progress["value"] = self.smooth_value
self.root.after(15, self.animate_progress)
๐ฏ This creates a smooth animated loading effect.
๐ฐ Step 9: Display Prediction Result
def show_result(self, price):
self.result_label.config(
text=f"Predicted Price: ${price:,}"
)
โ Formats numbers nicely
โ Updates UI safely from worker callbacks
โถ๏ธ Step 10: Run the Application
if __name__ == "__main__":
app = AutoValueApp()
app.run()
๐ Your AI-powered desktop app is now live!
๐ Final Thoughts
Youโve learned how to:
Combine Machine Learning + GUI
Use threads to keep apps responsive
Build a clean, professional Python desktop app
๐ Full Project on GitHub:
https://github.com/rogers-cyber/python-tiny-tools/tree/main/Car-price-prediction-GUI

Top comments (0)