Python Forum

Full Version: Return string from Javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to get a string returned from JavaScript but cannot find a good way. Like in the code below, is there a way to get content of 'substring' in Java returned to python code so I can print() it? Thanks.

import wx
import wx.html2 as Browser

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Youtube Downloader", size=(1450, 750), pos = (0, 0))
        wx.Panel(self)
        self.SetBackgroundColour(wx.Colour(248,248,248))
        self.URL = 'https://www.google.com'
        self.wv = Browser.WebView.New(self, url=self.URL, pos=(0, 35), size=(1450,750))
        self.Bind(Browser.EVT_WEBVIEW_LOADED, self.On_Load, self.wv)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.wv)
        self.SetSizer(sizer)
        self.wv.LoadURL(self.URL)
    def On_Load(self, event):
        self.wv.RunScript("""
            substring = 'Hello World!'.substr(0,5);
            alert(substring);
        """)
        print('substring')
if __name__ == "__main__":
    app = wx.App()
    win = Frame()
    win.Show()
    app.MainLoop()