Created
January 6, 2020 12:18
-
-
Save Ch3shireDev/ef120a68e3a23abf27cf49edab718b7f to your computer and use it in GitHub Desktop.
Simple Brython usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>BrytPage</title> | |
| <base href="/"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <link rel="icon" type="image/x-icon" href="favicon.ico"> | |
| <link | |
| href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" | |
| rel="stylesheet" | |
| integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" | |
| crossorigin="anonymous"> | |
| <script | |
| src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.6/brython.js"></script> | |
| <script type="text/python"> | |
| import javascript | |
| import browser | |
| def fun(value): | |
| return eval(value) | |
| browser.window.fun = fun | |
| </script> | |
| </head> | |
| <body onload="brython()" class="p-5"> | |
| <div class="row m-5 p-5 shadow border rounded"> | |
| <div class="input-group mb-3"> | |
| <div class="input-group-prepend"> | |
| <span class="input-group-text">Input</span> | |
| </div> | |
| <input id="input" type="text" class="form-control" | |
| value="2+3**2"> | |
| </div> | |
| <div class="input-group"> | |
| <div class="input-group-prepend"> | |
| <span class="input-group-text">Output</span> | |
| </div> | |
| <textarea id="output" class="form-control" aria-label="With | |
| textarea"></textarea> | |
| </div> | |
| <div id="process" class="btn btn-lg btn-primary shadow m-5">abc</div> | |
| </div> | |
| <script> | |
| document.getElementById("process").onclick = function(){ | |
| var value = document.getElementById("input").value; | |
| var result = fun(value); | |
| document.getElementById("output").value = result; | |
| } | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment