tkinter-WebView2 widget, based on WebView2.Core
Project description
tkwebview2
tkinter浏览器-网页组件,tkwebview2登场!!!
基于pythonnet-webview绑定和WebView2.Core,将受到微软WebView2的持续改进支持,外观和效能相比tkinterie
得到大幅度改进。
依赖
以下是tkwebview2
的依赖库:
- pythonnet(clr)
- pywebview(webview)
使用方法
WebView2(master,width:int,height:int,url:str='',**kw)
'''
master::父组件
width::初始宽度
height::初始高度
url::网址或html文件,可以为空
**kw::其它Frame参数
'''
例子:
from tkinter import Tk
from tkwebview2.tkwebview2 import WebView2
root=Tk()
root.title('pywebview for tkinter test')
root.geometry('1200x600+5+5')
frame=WebView2(root,500,500)
frame.load_html('<h1>hi hi hi</h1>')
frame.pack(side='left')
frame2=WebView2(root,500,500)
frame2.load_url('https://smart-space.com.cn/')
frame2.pack(side='right',fill='x',expand=True)
root.mainloop()
方法
get_url()
返回当前url。
evaluate_js(self,script)
执行JavaScript代码,并返回最终结果。
load_css(self,css)
加载CSS样式。
load_html(self,content,base_uri=None)
加载HTML代码,base_uri
为基本URL,默认为本程序启动目录。
load_url(self,url)
加载全新url。
判断WebView2 runtime是否存在并处理
tkwebview2提供了两个函数:have_runtime
, install_runtime
。
have_runtime()
判断运行环境是否存在,存在返回True,不存在返回False。
from tkwebview2.tkwebview2 import have_runtime
print(have_runtime())
install_runtime()
下载并安装运行环境。
from tkwebview2.tkwebview2 import have_runtime, install_runtime
if not have_runtime():
install_runtime()
注意:该函数会暂停程序运行,直到安装界面被用户手动关闭。期间,会下载安装程序到D盘,安装完成后会自动删除。
What's new
-2.0.1-[fix]
Add try ... except ...
to avoid error when importing as a test or a package.
-2.0.0-
You can use function have_runtime
and install_runtime
to check or download WebView2 Runtime in your application conveniently.
-1.2.0-
You can use it when you add a WebView in your window separately. However, you should destroy it when you want to close a window or a widget.
-1.1.0-
Upload to PYPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for tkwebview2-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75139939735b9a59f48eb12c53695870c03b3c03c314ae7321950754176b894b |
|
MD5 | 18a0d651b0a4e37b2d8e0ba68792fdc6 |
|
BLAKE2b-256 | d2f086ab33d12fa9189af85e840c940896df35ab5efc00fe8a450b4b93d4848f |