如何在Python的tkinter应用程序中嵌入HTML iframe?

huangapple go评论134阅读模式
英文:

how to embed html iframe on Python tkinter app

问题

我想知道如何将来自Web应用的图表iframe HTML内容嵌入到tkinter中。

我还没有尝试过,但我看到了一些模块,比如tkhtmlview,但它不是一个网页浏览器,所以它可能不太适合我想要的功能。

我还看到了CEFPython,但最新版本是在2021年2月发布的。

还有其他选择吗?

谢谢。

英文:

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

答案1

得分: 1

使用tkinter的Frame小部件和"pywebview"库中的"WebView"小部件。
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="加载网页", command=load_webpage)
button.pack()

root.mainloop()

上面的代码演示了如何在tkinter中嵌入HTML iframe。

英文:

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

huangapple
  • 本文由 发表于 2023年3月7日 14:31:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定