htmlpython-3.xtkinteriframe

how to embed html iframe on Python tkinter app


I would like to know how its possible to embed a chart iframe html content from a web app into tkinter

I haven't tried yet, but I have seen a few modules such as tkhtmlview, but it isn't a web browser, so it probably won't work well for what I am looking for

I've seen also CEFPython, but the latest release dates to Feb 2021.

Any other choices?

Thanks


Solution

  • Use the tkinter Frame widget and the "WebView" widget from the "pywebview" library. pip install pywebview

    import tkinter as tk
    import webview
    
    def load_webpage():
        webview.load_url('path/to/your/html/file.html')
    
    root = tk.Tk()
    frame = tk.Frame(root)
    frame.pack()
    
    button = tk.Button(frame, text="Load webpage", command=load_webpage)
    button.pack()
    
    root.mainloop()
    

    The above code demonstrates the way you can achieve embedding html iframe in tkinter