[[oktatas:programozás:python:wxpython_gui|< wxPython GUI]] ====== wxPython html2 ====== * **Szerző:** Sallai András * Copyright (c) Sallai András, 2020 * [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== Telepítés ===== A wx.html csak szimpla HTML értelmezést tud, de a wx.html2 CSS és JavaScript értelmezésre is képes. wx.html telepítés: apt install libwebkit2gtk-4.0-dev wx.html2 telepítés: apt install python3-wxgtk-webview4.0 ===== Egyszerű böngésző ===== import wx import wx.html2 class MainFrame(wx.Frame): def __init__(self, parent): super(MainFrame, self).__init__(parent) self.InitUI() self.InitLayout() def InitUI(self): self.SetSize((800,600)) self.address = wx.TextCtrl(self) self.goButton = wx.Button(self, label='Go') self.goButton.Bind(wx.EVT_BUTTON, self.onClickGoButton) self.browser = wx.html2.WebView.New(self) self.browser.Bind(wx.html2.EVT_WEBVIEW_NAVIGATING, self.onWebViewNavigating) self.browser. self.toolBar = self.CreateToolBar(wx.TB_HORIZONTAL, wx.ID_ANY) self.backTool = self.toolBar.AddTool(1001, 'Vissza', wx.Bitmap('back.png')) self.Bind(wx.EVT_TOOL, self.onClickBackTool, self.backTool) self.toolBar.Realize() def InitLayout(self): rootBox = wx.BoxSizer(wx.VERTICAL) headBox = wx.BoxSizer(wx.HORIZONTAL) workBox = wx.BoxSizer(wx.HORIZONTAL) rootBox.Add(headBox, 0, wx.EXPAND) rootBox.Add(workBox, 1, wx.EXPAND) headBox.Add(self.address, 1) headBox.Add(self.goButton, 0) workBox.Add(self.browser, -1, wx.EXPAND | wx.ALL, 5) self.SetSizer(rootBox) def onClickGoButton(self, event): self.browser.LoadURL(self.address.GetValue()) def onWebViewNavigating(self, event): url = event.GetURL() print(url) def onClickBackTool(self, event): self.browser.GoBack() import wx from MainFrame import MainFrame class Bongeszo(wx.App): def OnInit(self): frame = MainFrame(None) frame.Show() return True app = Bongeszo() app.MainLoop()