DEV Community

Mate Technologies
Mate Technologies

Posted on

Build a Laptop Price Predictor Desktop App with Python & Tkinter

In this tutorial, we’ll build a Laptop Price Predictor desktop app using Python, tkinter, and ttkbootstrap. This beginner-friendly guide breaks everything down step by step so you can follow along and understand how it works.

We’ll create an app where users can select a laptop’s brand, CPU, RAM, storage, and GPU, and the app predicts its price.

Step 1: Set up your project

First, make sure you have Python installed (>=3.8). Then install ttkbootstrap for a modern UI:

pip install ttkbootstrap
Enter fullscreen mode Exit fullscreen mode

We'll also use tkinter, which comes pre-installed with Python.

Step 2: Create a Python file

Create a new Python file, for example:

laptop_price_predictor.py

This will be your main app file.

Step 3: Import the required libraries

At the top of your file, import tkinter and ttkbootstrap:

import tkinter as tk
from tkinter import messagebox
import ttkbootstrap as tb
from ttkbootstrap.constants import *
Enter fullscreen mode Exit fullscreen mode

Explanation:

tkinter is the built-in Python library for desktop GUIs.

ttkbootstrap gives your app a modern look.

messagebox can be used for pop-ups, and constants are helper values for styling.

Step 4: Create a mock prediction function

For now, we’ll use a simple function to predict prices based on laptop specs:

def predict_price(specs):
    base_price = 300
    cpu_factor = {"i3": 100, "i5": 200, "i7": 350, "Ryzen 3": 90, "Ryzen 5": 180, "Ryzen 7": 320}
    ram_factor = {4: 50, 8: 100, 16: 200, 32: 350}
    storage_factor = {"HDD": 50, "SSD": 150, "Hybrid": 100}
    gpu_factor = {"Integrated": 0, "GTX 1650": 200, "RTX 3050": 350, "RTX 4070": 600}
    brand_factor = {"Dell": 100, "HP": 80, "Lenovo": 70, "Asus": 90, "Apple": 400}

    price = base_price
    price += cpu_factor.get(specs["CPU"], 0)
    price += ram_factor.get(specs["RAM"], 0)
    price += storage_factor.get(specs["Storage"], 0)
    price += gpu_factor.get(specs["GPU"], 0)
    price += brand_factor.get(specs["Brand"], 0)
    return price
Enter fullscreen mode Exit fullscreen mode

Explanation:

This is a simple “mock model” to calculate a price.

Each spec contributes a fixed value to the base price.

Later, you can replace this with a real machine learning model.

Step 5: Build the main app class

We’ll wrap the app in a class for better organization:

class LaptopPriceApp:
    APP_NAME = "LaptopPricePredictor"
    APP_VERSION = "1.0"

    def __init__(self):
        self.root = tb.Window(themename="darkly")
        self.root.title(f"{self.APP_NAME} v{self.APP_VERSION}")
        self.root.geometry("600x550")

        self._build_ui()
        self._apply_styles()
Enter fullscreen mode Exit fullscreen mode

Explanation:

tb.Window creates the main window with a modern theme.

_build_ui() will add all our widgets.

_apply_styles() sets custom fonts and styles.

Step 6: Add UI elements

We’ll create labels, dropdowns, and a button for inputs:

def _build_ui(self):
    main = tb.Frame(self.root, padding=20)
    main.pack(fill=tk.BOTH, expand=True)

    tb.Label(main, text="💻 Laptop Price Predictor", font=("Segoe UI", 20, "bold")).pack(pady=(0,10))
    tb.Label(main, text="Enter your laptop specs below:", font=("Segoe UI", 10, "italic"), foreground="#9ca3af").pack(pady=(0,20))

    # Brand
    tb.Label(main, text="Brand").pack(anchor=W)
    self.brand_combo = tb.Combobox(main, values=["Dell","HP","Lenovo","Asus","Apple"])
    self.brand_combo.pack(fill=X, pady=(0,10))
    self.brand_combo.set("Dell")
Enter fullscreen mode Exit fullscreen mode

Tip:

Use .pack() or .grid() to organize widgets.

.Combobox() allows users to select options from a dropdown.

Step 7: Add the rest of the inputs

# CPU
tb.Label(main, text="CPU").pack(anchor=W)
self.cpu_combo = tb.Combobox(main, values=["i3","i5","i7","Ryzen 3","Ryzen 5","Ryzen 7"])
self.cpu_combo.pack(fill=X, pady=(0,10))
self.cpu_combo.set("i5")

# RAM
tb.Label(main, text="RAM (GB)").pack(anchor=W)
self.ram_combo = tb.Combobox(main, values=[4,8,16,32])
self.ram_combo.pack(fill=X, pady=(0,10))
self.ram_combo.set(8)

# Storage
tb.Label(main, text="Storage Type").pack(anchor=W)
self.storage_combo = tb.Combobox(main, values=["HDD","SSD","Hybrid"])
self.storage_combo.pack(fill=X, pady=(0,10))
self.storage_combo.set("SSD")

# GPU
tb.Label(main, text="GPU").pack(anchor=W)
self.gpu_combo = tb.Combobox(main, values=["Integrated","GTX 1650","RTX 3050","RTX 4070"])
self.gpu_combo.pack(fill=X, pady=(0,20))
self.gpu_combo.set("Integrated")

Step 8: Add the Predict button and result label
self.predict_btn = tb.Button(main, text="💰 Predict Price", bootstyle=SUCCESS, command=self.predict)
self.predict_btn.pack(pady=(0,10))

self.result_label = tb.Label(main, text="", font=("Segoe UI", 16, "bold"))
self.result_label.pack(pady=(10,0))
Enter fullscreen mode Exit fullscreen mode

Explanation:

Clicking the button calls self.predict().

The result label shows the predicted price.

Step 9: Define the predict function

def predict(self):
    specs = {
        "Brand": self.brand_combo.get(),
        "CPU": self.cpu_combo.get(),
        "RAM": int(self.ram_combo.get()),
        "Storage": self.storage_combo.get(),
        "GPU": self.gpu_combo.get()
    }
    price = predict_price(specs)
    self.result_label.config(text=f"Estimated Price: ${price}")
Enter fullscreen mode Exit fullscreen mode

Tip:

.get() retrieves the user’s choice from each combobox.

self.result_label.config() updates the UI dynamically.

Step 10: Add some custom styles
def _apply_styles(self):
    self.root.style.configure("TButton", font=("Segoe UI", 12))
Enter fullscreen mode Exit fullscreen mode

This makes the button text more readable.

Step 11: Run the app

Finally, add the main loop to start the app:

if __name__ == "__main__":
    app = LaptopPriceApp()
    app.run()
Enter fullscreen mode Exit fullscreen mode

✅ Step 12: Try it out!

Run your script:

python laptop_price_predictor.py
Enter fullscreen mode Exit fullscreen mode

Select specs, click Predict Price, and see the estimated price instantly! 🎉

Optional: Make it better

Replace the mock predict_price() with a real ML model.

Add more laptop brands or GPUs.

Improve UI with icons or better layouts.

Source Code

You can also check the full project on GitHub:

https://github.com/rogers-cyber/python-tiny-tools/tree/main/Laptop-price-prediction-app

Top comments (0)