-
Notifications
You must be signed in to change notification settings - Fork 518
Writing an Android and iOS application using Xamarin.Forms
With Brython
you can write applications in Python that run in modern browsers, including most of smartphones browsers. But you can also write native Android and iOS applications : this page explains how to do it, taking the example of a basic "Hello world" application using Xamarin.Forms
- Installation Xamarin.Forms and development envoriment
The first step is to install the latest version of Visual Studio (https://docs.microsoft.com/en-us/xamarin/get-started/installation/?pivots=windows) and if you prefer as me JetBrain IDE-s then install Rider
- Main View of Application
Xamarin.Forms
is cross-platform framework that allow to write once and run everywhere UI Application (on most of the platforms ;))
The Main Page of entire application is set in App.cs
of BrythonMobile
project
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace BrythonMobile
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new LocalHtmlBaseUrl {Title = "BaseUrl" };
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
- Write the Brython application
In this example, we only use brython.js and index.html holds a basic "Hello" application:
<!DOCTYPE html>
<html>
<head>
<title>Hello world</title>
<meta charset="utf-8">
<script src="brython.js"></script>
</head>
<body onload="brython(1)">
<script type="text/python">
from browser import document, alert
def echo(ev):
alert("Hello {} !".format(document["zone"].value))
document["test"].bind("click", echo)
</script>
<p>Your name is : <input id="zone" autocomplete="off">
<button id="test">click !</button>
</body>
</html>
Test project you can find by the following link: BrythonMobile Test Project