Skip to main content

tkinterIE

基于InternetExplorer.Application的WebView组件。

使用方法

WebView(master,width:int,height:int,url:str='',**kw)
'''
master::父组件
width::初始宽度
height::初始高度
url::网址或html文件,可以为空
**kw::其它Frame参数
'''

例子:

from tkinter import Tk
from tkinterie.tkinterIE import WebView
import clr
clr.AddReference('System.Threading')
from System.Threading import Thread,ApartmentState,ThreadStart

def main():
    a=Tk(classname='test tkinterie')
    a.geometry('1200x700')
    w=tkinterIE.WebView(a,1200,700,'www.baidu.com')
    w.pack()
    a.mainloop()

if __name__=='__main__':
    t = Thread(ThreadStart(main))
    t.ApartmentState = ApartmentState.STA
    t.Start()
    t.Join()

tkinter主窗口必须在STA线程模式下运行,防止WebBrowser卡死。


方法

navigate(url:str)

指向一个网址或者是html文件路径。

goback()

上一页

goforward()

下一页

gosearch()

返回默认搜索界面

gohome()

返回初始界面

refresh()

刷新当前界面


一些绑定事件

本部分只作为参考,具体见微软发布的说明文章。

def main():
    a=Tk()
    a.geometry('1200x600')
    w=WebView(a,1200,550,'www.baidu.com')
    w.pack(side='bottom',fill='both')

    w.ie.IsWebBrowserContextMenuEnabled=False#禁用快捷键、菜单
    w.ie.Navigating+=before_navigate#打开新的链接
    w.ie.NewWindow+=before_window#打开新的窗口
    
    a.mainloop()
def before_navigate(sender,e):#显示新链接
    print(e.Url)
def before_window(sender,e):#在本控件打开新窗口
    a=sender.Document.ActiveElement.GetAttribute("href")
    sender.Navigate(a)
    e.Cancel=True


if __name__ == "__main__":
    t = Thread(ThreadStart(main))
    t.ApartmentState = ApartmentState.STA
    t.Start()
    t.Join()

What's new

-1.5.0-

Bind some method.

-1.4.0-

Add some example about binding some events of WebBowser in Python.

-1.3.0-

Use WinForms' WebBrowser, but it must runs in STA thread mode.

-1.2.0-

WebView will be destroyed when father widget destroys.

-1.1.0-

WebView can resize itself when father widget's size changes.

-1.0.0-

Upload to PYPI.

Metadata

Release files for tkinterie 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for tkinterie 1.5.0
File Interpreter ABI Platform
tkinterie-1.5.0-py3-none-any.whl Python 3 none any Details

Release files / tkinterie-1.5.0-py3-none-any.whl

Download URL tkinterie-1.5.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4fff27d75bb1a3daacdf397b337f69ce0f09f783058fc9ba369678da1611c67
BLAKE2b-256 checksum
How to use checksums
7064d1ec88e145980dea86bebf5e6a14fe7cabec461064a1f758a1a42064eff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.5.0 This release

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page