我尝试制作一个简单的应用程序,在单击放置在“屏幕一”上的按钮后,可以在 Kivy 中打开一个网页。
我使用了这个主题(Python - 在应用程序中显示网络浏览器/iframe)作为参考,但我不明白如何使用 Michael 提供的代码......
所以我尝试了这个……当我启动 apk(使用 Buildozer 构建)时,它不起作用:')
import kivy
kivy.require('1.9.2')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
# MICHAEL'S CODE
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 …Run Code Online (Sandbox Code Playgroud)