如何在面板上绑定cefpython(wxpython)?

How to bind cefpython on the panel(wxpython)?

下面是 wxpython GUI 的指定代码,您可以在其中观察到我使用了 wx.html2.WebView 来渲染网页在面板上。是否可以将相同代码的 webview 替换为 cefpython

我还得到了启动自己框架的 cefpython code。我不想打开它自己的框架,而不是它绑定在 wxpython 面板 上。你可以在下面看到cefpython代码。

1.wxpython 界面代码

import wx
import sys
import wx.html2 

def main(args):
    app = CefApp(False, args)
    app.MainLoop()

class MainPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.frame = parent

        sizer = wx.BoxSizer(wx.VERTICAL) 
        self.wv = wx.html2.WebView.New(self)
        closeBtn = wx.Button(self, label="X", size=(30, 30))
        closeBtn.Bind(wx.EVT_BUTTON, self.onClose)
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox= wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(closeBtn, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        vbox.Add(hbox, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.SetSizer(vbox)
        vbox.SetSizeHints(self)
        self.SetWindowStyle(wx.STAY_ON_TOP)

        sizer.Add(closeBtn, 0, wx.ALIGN_RIGHT | wx.ALL)
        sizer.Add(self.wv, 1, wx.EXPAND)
        self.SetSizer(sizer)

        self.wv.LoadURL("http://google.com")

    def onClose(self, event):
        dlg = DialogBox()
        dlg.ShowModal()

class MyFrame(wx.Frame):

    def __init__(self, args):
        wx.Frame.__init__(self, None, title="ESSB Demo")
        self.url = args
        self.browser_panel = MainPanel(self)
        self.ShowFullScreen(True)

2.CefPython代码.

from cefpython3 import cefpython as cef
import platform
import sys


def main():
    sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
    cef.Initialize()
    cef.CreateBrowserSync(url="https://www.google.com/")
    cef.MessageLoop()
    cef.Shutdown()

请指教。

您提供的cefpython代码来自hello_wordl.py示例。该示例不支持 wxpython。 wxpython.py 示例中提供了在面板内的 wxpython 应用程序中嵌入 CEF 浏览器的示例:

https://github.com/cztomczak/cefpython/blob/master/examples/wxpython.py