Welcome folks today in this blog post we will be using the google maps
api inside the tkinter
gui window and we will be placing markers
using the tkintermapview
library. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below library using the pip
command as shown below
pip install tkintermapview
After that we need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 |
import tkinter from tkintermapview import TkinterMapView root_tk = tkinter.Tk() root_tk.title("map_view_simple_example.py") root_tk.geometry(f"{600}x{400}") |
As you can see we are importing the tkintermapview
library at the top and then we are setting the title
of the gui window and then we are setting the geometry
which is the width and height of the gui window.
1 2 3 |
widgetmap_widget = TkinterMapView(root_tk, width=600, height=400, corner_radius=0) widgetmap_widget.pack(fill="both", expand=True) |
As you can see we are initializing the TkinterMapView
library and inside that we are passing the width
and height
. And then we are adding this tkintermapview
into the gui window using the pack()
method.
1 2 3 |
widgetmap_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22) widgetmap_widget.set_address("Wellington New Zealand", marker=True) root_tk.mainloop() |
As you can see we are setting the src
of the map widget
and then we are setting the address of the map widget and based upon this address we are plotting the red
markers on the map. And then we are starting the tkinter
app.