2
Home

yutent edited this page 2023-08-31 19:11:24 +08:00

安装

apt install python3-webengine-gtk3

使用


import gi, os
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk
from webengine.gtk3 import WebEngine, create_setting, create_hmr_server

__dir__ = os.path.dirname(os.path.realpath(__file__))
web_root = os.path.join(__dir__, './webapp')

win = Gtk.window()
web = WebEngine()
hmr = create_hmr_server()

web.set_root(web_root)

web.use(hmr).load()
# 默认会加载 '/index.html,  上面的写法等价于 web.use(hmr).load('/index.html')

win.add(web)
Gtk.main()