It has been asked in the forum: I want to make a python code editor using App Inventor.
Is it possible to execute code in some way or the other and show the output?
Yes, this is possible!
To find a solution to this problem, I looked around in the internet and found Skulpt: Python. Client side. Skulpt is an entirely in-browser implementation of Python. No preprocessing, plugins, or server-side support required, just write Python and reload. Thank you Scott Graham!
I uploaded the jQuery library, 2 Skulpt libraries and the modified example html code
(which has been provided at www.skulpt.org) as assets into App Inventor.
The Python code examples are available as text files and also uploaded as assets. The code to run will be transferred in the WebViewString property to the webviewer. After processing, the result will be provided back to App Inventor in the page title of the webviewer.
The tools extension offers the method PathToAssets which always returns the correct path to the assets.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta name="author" content="puravidaapps.com"> <!-- more about Skulpt see http://www.skulpt.org Thank you Scott Graham! -->
<title>App Inventor and Skulpt running some Python</title> </head> <body> <pre id="output"></pre> <!-- If you want turtle graphics include a canvas --> <canvas id="mycanvas" ></canvas>
Tested successfully on Nexus 5 running Android 4.4.4.
Comic provided by xkcd.com. Thank you.
If you find this example helpful and you are using it in one of your projects,
be nice and donate a small amount!
or donate some mBTC to Address:
Thank you! Taifun
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.