TkinterWeb icon indicating copy to clipboard operation
TkinterWeb copied to clipboard

HtmlFrame widget is trying to interpret the file path as a web URL instead of a local file path when I try to load a folium map.

Open naiyar5j opened this issue 1 year ago • 1 comments

When I try to load a folium map in HtmlFrame, I got an error. The code is below: from tkinterweb import HtmlFrame from tkinterweb import HtmlFrame #import the HTML browser try: import tkinter as tk #python3 except ImportError: import Tkinter as tk #python2 import folium

root = tk.Tk() #create the tkinter window frame = HtmlFrame(root) #create HTML browser

Create a folium map

m = folium.Map(location=[37.7749, -122.4194], zoom_start=12)

Save the map as an HTML file

m.save("F:/py2exedata/map.html") frame.load_website("file:///F://py2exedata//map.html") #load a website frame.pack(fill="both", expand=True) #attach the HtmlFrame widget to the parent window

root.mainloop()

The error is below: Starting TkinterWeb for 64-bit Windows with Python 3.10.9.

Tkhtml3 successfully loaded from F:\py2exedata\myenv\Lib\site-packages\tkinterweb\tkhtml\Windows\64-bit.

Welcome to TkinterWeb 3.23! https://github.com/Andereoo/TkinterWeb

Debugging messages are enabled. Use the parameter messages_enabled = False when calling HtmlFrame() to disable these messages.

Connecting to file:.

An error has been encountered while loading http://file:///F://py2exedata//map.html: <urlopen error [Errno 11001] getaddrinfo failed>.

naiyar5j avatar Apr 20 '24 10:04 naiyar5j

Hi! You need to use load_url or load_file instead of load_website.

load_website is mostly a convenience function forces the page to be opened as a website, even though you specify "file://" in the url . Similarly, load_file instead forces the page to be opened as a file, so passing both "file:///F://py2exedata//map.html" and "F://py2exedata//map.html" should load the file. load_url will load whatever url is passed to it without altering it.

Andereoo avatar Apr 20 '24 10:04 Andereoo