Skip to main content

How to Build a Python Location Tracker for Desktop Apps?

 

ttkbootstrap Mapview
This tutorial will show you how to create an interactive map application that allows users to input geographic coordinates and visualize locations on an interactive map using Python's Tkinter GUI framework enhanced with TTKBootstrap styling and the TkinterMapView widget. 

Prerequisite:

This tutorial is part of the standalone tutorial.

📚 View the 
standalone tutorial


Preliminary 
Before I begin, it is recommended to activate the virtual environment before installing the relevant dependencies.
python -m venv venv
venv\Scripts\activate   
pip install ttkbootstrap tkintermapview
As usual, we need to import the relevant module and set the root values
from tkinter import *
import ttkbootstrap as tb
import tkintermapview
from ttkbootstrap.dialogs import Messagebox

root = tb.Window(themename='darkly')
root.title('Find My Map')
root.geometry("1200x1200")
I would like to divide it into three sections. 

a) Input Panel Layout, 
The headers are mainly a label with a map emoji. 
The main layout contains labels and input fields for latitude and longitude, followed by 2 buttons: set position and clear entries. They are set on the same row for easy navigation.

Why am I?

# Main header label for the application
header_label = tb.Label(root, text="Where Am I? 🗺️", font=("Helvetica", 24), 
                        bootstyle="success-inverse")
header_label.pack(pady=10)

# Create a frame to contain coordinate input controls
My_frame = tb.Frame(root, bootstyle="info")
My_frame.pack(pady=10, padx=30, fill="x", expand=False)

# Configure grid column weights for equal width distribution across 5 columns
for i in range(6):  # 6 columns (0-5)
    My_frame.columnconfigure(i, weight=1)

# Define a consistent font for input controls
my_font = ("Roboto", 12)

# Latitude label and input field
my_vertical_cordinate = tb.Label(My_frame, text="Latitude:", 
                                 font=my_font,
                                 bootstyle="info-inverse")
my_vertical_cordinate.grid(row=0, column=0, pady=5, padx=5, sticky=EW)

latitude_entry = tb.Entry(My_frame, bootstyle="info")
latitude_entry.grid(row=0, column=1, pady=5, padx=5, sticky=EW)

# Longitude label and input field
my_horizontal_cordinate = tb.Label(My_frame, text="Longitude:",
                                   font=my_font,
                                   bootstyle="info-inverse")
my_horizontal_cordinate.grid(row=0, column=2, pady=5, padx=5, sticky=EW)

longitude_entry = tb.Entry(My_frame)
longitude_entry.grid(row=0, column=3, pady=5, padx=5, sticky=EW)

# Button to set map position using entered coordinates
# Converts string inputs to floats and calls set_position method
set_position_button = tb.Button(My_frame, text="Set Position", 
                                bootstyle=("danger", "outline"),
                                command=set_map_position)
set_position_button.grid(row=0, column=4, pady=5, padx=5, sticky=EW)

# Button to clear the latitude and longitude entry fields
clear_button = tb.Button(My_frame, text="Clear Entries", 
                         bootstyle=("warning", "outline"),
                         command=clear_entries)
clear_button.grid(row=0, column=5, pady=5, padx=5, sticky=EW)
b) Mapview 
Layout 
Basically, a labelframe from Tkinter is required to display the map frame.

Map

# LabelFrame container for the map widget
my_label = LabelFrame(root, text="My map")
my_label.pack(pady=20, padx=20, fill="both", expand=True)

# Create map widget with specified dimensions and no rounded corners
map_widget = tkintermapview.TkinterMapView(my_label, width=1100, 
                                           height=1100, corner_radius=0)
map_widget.pack()

# Set initial zoom level (15 is a moderately close view)
map_widget.set_zoom(15)
c) The Main Function
  • Accepts latitude and longitude values through input fields
  • Validates numeric input format
  • Shows a scrollable/zoomable world map using OpenStreetMap tiles

  • Centers the map on specified coordinates
  • Places a marker at the target location

  • Instantly jumps to any location worldwide

  • Reset input fields for new search

Show error
def set_map_position():
    try:
        # Attempt to get and convert latitude input to a floating-point number
        lat = float(latitude_entry.get())
        # Attempt to get and convert longitude input to a floating-point number  
        lon = float(longitude_entry.get())
        # Center the map widget on the specified coordinates
        map_widget.set_position(lat, lon)     
    except ValueError:
        # This block executes if float() conversion fails (non-numeric input)
        # Display an error dialog box to inform the user
        Messagebox.show_error(
            title="Invalid coordinates.",  # Dialog title
            message="Please enter numeric values!!!"  # Error message
        )  
        # Clear the input fields after user acknowledges the error
        clear_entries()

def clear_entries():
       # Delete all text from latitude entry field (from position 0 to END)
       latitude_entry.delete(0, END)
       # Delete all text from longitude entry field (from position 0 to END)
       longitude_entry.delete(0, END)
Final Wrap-Up

This completes our tutorial on building a geographic MapViewer application with Python. We've successfully created a functional desktop application that transforms numerical coordinates into visual map locations through an intuitive graphical interface.

Published: Jan 2026
Last Updated: Jan 2026
---------------------------------------------------------------------------------------------------------------------------------------------------

🎁 Get Your FREE Flask Cheat Sheet

Join 500+ Python learners and receive this printable Flask Cheat Sheet instantly. Plus, get new Flask tutorials delivered to your inbox.

✓ Practical coding tutorials
✓ Automation tips for SMEs
✓ New project ideas and templates

-----------------------------------------------------------------------------------------------------------------------------
Need a similar system for your business? 
I build custom Flask web applications and Python automation solutions for SMEs and solopreneurs. 


-----------------------------------------------------------------------------------------------------------------------------

About the Author

Kelvin Loh is a Python developer focused on Flask, desktop applications, and business automation solutions. He shares practical tutorials and real-world coding projects to help developers and small businesses build useful applications.

Comments

Popular Posts

How to Build an Audiobook Workflow Desktop System with Python?

In this tutorial, we will build a simple audiobook player using Python and CustomTkinter. You will learn how to convert text into speech using gTTS and play it with PyGame. We will also implement play, pause, and stop controls, like those in a real audio player. By the end, you will have a clean and functional desktop audiobook app. Prerequisite: This tutorial is part of the standalone tutorial. 📚 View the standalone tutorial Preliminary   Before I begin, it is recommended to activate the virtual environment before installing the relevant dependencies. python -m venv venv venv\Scripts\activate pip install customtkinter pillow gTTS pygame CTkMessagebox pypdf Then, the following steps include setting up the file structure, app.py, and two additional folders: the uploads and media folders. The media folder contains the icons necessary to build the app; there are read, pause, and stop icons, as shown on the diagram. Step 1: Build up the app interface I have 4 sections here: the...

How to Set Up PgAdmin and Adminer Using Docker Compose?

If you are new to database management with Docker, this tutorial will guide you through setting up both PgAdmin and Adminer using Docker containers. By containerising these tools, you can quickly launch lightweight and portable database management environments without installing them directly on your operating system. This approach also makes it easier to manage configurations, updates, and multiple projects across different devices.