Tkinter Map View error: 'PhotoImage' object has no attribute '_PhotoImage__photo'

281 Views Asked by At

I am trying to draw a map view within a frame, and draw polygons of local authorities (for the user to click to select).

When running the code I get the following error, although the widget is working:

AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'

The code I am using is the following:

import tkinter as tk
import tkintermapview
import json
import itertools

# create tkinter window
root_tk = tk.Tk()
root_tk.geometry(f"{1000}x{700}")
root_tk.title("map_view_polygon_example.py")

# create map widget
map_widget = tkintermapview.TkinterMapView(root_tk, width=800, height=600, corner_radius=0)
map_widget.pack(fill="both", expand=True)
map_widget.set_position(53.46,-2.250)  # UK
map_widget.set_zoom(8)

# polygon click
def UpdateMap(event=None):
    tk.messagebox.showinfo("A local authority")

# get polygon shape
d = open('LA_shape.json')
shape = json.load(d)
shape = shape['features']

# for each local authority
for x in range(len(shape)):
    coord = shape[x]
    coord = coord['geometry']
    coord = coord['coordinates']
    coord = list(itertools.chain(*coord))
    coord = list(itertools.chain(*coord))
    
    # swap lat / long to long / lat
    for x in range(len(coord)):
        coord[x][0], coord[x][-1] = coord[x][-1], coord[x][0]

        map_widget.set_polygon(coord,
            # fill_color=None,
            # outline_color="red",
            # border_width=12,
            command=UpdateMap,
            name="local_authority_polygon")
    
root_tk.mainloop()

Source file for LA_shape.json here

0

There are 0 best solutions below