tests/Webdev/python.html
2024-03-10 16:02:52 +01:00

59 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Your existing head content -->
<!-- Brython CDN -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.10.0/brython.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<!-- Search Bar -->
<input type="text" class="form-control" id="searchInput" placeholder="Type something and press Enter">
<!-- Results Box -->
<div id="results-box" class="mt-3"></div>
</div>
</div>
</div>
<!-- Your existing Bootstrap JS and Popper.js -->
<!-- Custom JavaScript for handling the search -->
<script type="text/python">
from browser import document
def handle_search():
search_input = document['searchInput'].value.strip()
if search_input:
# Process the search term (replace this with your own logic)
result = process_search(search_input)
# Append result to the results box
results_box = document['results-box']
results_box.html += f'<p class="alert alert-success">{result}</p>'
# Clear the search input
document['searchInput'].value = ''
def process_search(search_term):
# Your Python function logic here
# For now, just returning the search term as an example
return f"Result: {search_term}"
# Attach the handle_search function to the Enter key event
document['searchInput'].bind('keyup', lambda ev: handle_search() if ev.key == 'Enter' else None)
</script>
<!-- Execute Brython script -->
<script type="text/javascript">
brython({debug:1, indexedDB:1});
</script>
</body>
</html>