Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created April 3, 2020 13:23
Show Gist options
  • Save tomhodgins/4c1c114d5ccade0d452a98dc3c302014 to your computer and use it in GitHub Desktop.
Save tomhodgins/4c1c114d5ccade0d452a98dc3c302014 to your computer and use it in GitHub Desktop.
<script type=module>
import computedVariables from 'https://unpkg.com/computed-variables/index.es.js';
computedVariables(
'--python',
(value, event, rule) => {
if ('brython' in window === false) {
const tag = document.createElement('script');
tag.onload = callback;
tag.src = 'https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython.js';
document.head.append(tag);
} else {
callback();
}
function callback() {
const python = document.createElement('script');
python.type = 'text/python';
python.textContent = rule.style.getPropertyValue('--python-value').replace(/\\;/g, ';\n');
document.head.append(python);
brython();
}
},
window,
['load']
)
</script>
<style>
#demo {
--python:
from browser import document, alert\;
def hello(ev): alert("hello from python in CSS!")\;
document["demo"].bind("click", hello)\;
;
}
</style>
<button id=demo>Click me</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment