Python - 在应用程序中显示Web浏览器/ iframe [英] Python - Showing a web browser/iframe right into the app
问题描述
我有一个脚本,如果对回答问题的人有帮助,就是使用kivy。
我想让它在运行时显示iframe类似的东西,而不是在浏览器中打开
。例如:
I have a script which if helpful to people answering questions, is using kivy. I want to have it show a iframe kind of thing right into it when run, instead of opening the browser. For example something like this:
def browser():
url = "google.com"
iframe(url)
browser()
显然这不起作用,因为python不是html。请记住,我不是试图在网上运行
这个脚本,而是在kivy启动器上运行。按照预期,它不应该打开
webbrowser,而是在内置于脚本中的框中显示页面。
Obviously this wouldnt work as python is not html. Keep in mind, I am not trying to run this script on the web, but on the kivy launcher. As intended, it should not open the webbrowser but instead show the page in a box built right into the script.
推荐答案
这是一个实际运行的例子,它可以在Kivy Launcher应用程序中运行:
Here's an actual running example which works right inside the "Kivy Launcher" app:
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
from kivy.uix.widget import Widget
from kivy.clock import Clock
from jnius import autoclass
from android.runnable import run_on_ui_thread
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.renpy.android.PythonActivity').mActivity
class Wv(Widget):
def __init__(self, **kwargs):
super(Wv, self).__init__(**kwargs)
Clock.schedule_once(self.create_webview, 0)
@run_on_ui_thread
def create_webview(self, *args):
webview = WebView(activity)
webview.getSettings().setJavaScriptEnabled(True)
wvc = WebViewClient();
webview.setWebViewClient(wvc);
activity.setContentView(webview)
webview.loadUrl('http://www.google.com')
class ServiceApp(App):
def build(self):
return Wv()
if __name__ == '__main__':
ServiceApp().run()
这篇关于Python - 在应用程序中显示Web浏览器/ iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!