問題描述
我有一個腳本,如果對人們回答問題有幫助的話,我正在使用 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 啟動器上.正如預期的那樣,它不應該打開瀏覽器,而是在腳本內置的框中顯示頁面.
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!