🐍 Introduction
In this tutorial, I'll show you how to create a simple WebView app using Python and Kivy. This app will display any website (like Google, YouTube, or your own) in an Android WebView.
We’ll use:
Python 💻
Kivy 🐍
Android (via Buildozer) 📱
Python Code (main.py)
from kivy.app import App
from jnius import autoclass
from kivy.clock import Clock
from android.runnable import run_on_ui_thread
from kivy.uix.widget import Widget
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity
@run_on_ui_thread
def create_webview(*args):
webview = WebView(activity)
webview.getSettings().setJavaScriptEnabled(True)
wvc = WebViewClient()
webview.setWebViewClient(wvc)
activity.setContentView(webview)
webview.loadUrl('https://littleone7a.blogspot.com/')
class Wv(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.__functionstable__ = {}
Clock.schedule_once(create_webview, 0)
class ServiceApp(App):
def build(self):
return Wv()
if __name__ == '__main__':
ServiceApp().run()
🌐 Final Output
Your app will open a WebView and load the website you specify inside the app! You can change the URL in webview.loadUrl("...")
.
Tags :
Python Kivy Apps , Python Kivy , Python Kivy WebView , Python Kivy WebApp ,Python Pyjnius , Python Android Apk , Python Buildozer , Android Python Kivy ,Kivy Applications ,