Manage Python code using HTML code

Greetings! I am currently working on a Robot control system and would like to be able to control it through a website that I have created. However, I am facing difficulties in connecting this to Python code to control the Raspberry Pi GPIO.

You can access the active version of my website at www.awesomecoding.co.uk, and below is the source code of the HTML:

<html>
<head>
    <style type="text/css">
        #commands{
            text-align: center;
            color: FF8300;
            font-size: 100px;
        }
        .controllbox{
            width: 610px;
            margin: 0 auto;
        }
        #arrowUp{
            text-align: center;
            position: static;
        }
        #arrowRight{
            text-align: right;
            position: static;
            margin-top: 0;
        }
        #arrowDown{
            text-align: center;
            position: static;
        }
        #arrowLeft{
            text-align: left;
            position: static;
            margin-top: -200px;

        }
        #stop{
            width: 120px; 
            height: auto;
            margin: 0 auto;
            margin-top: -65%;
            margin-left: 34%;
            text-align: center;
            position: static;


        }
    </style>
</head>
 <body>

    <h1 id="commands">Controll Me!!</h1>
    <div class="controllBox">
        <div id="arrowUp"><img src="arrowUp.jpg" class="controll" id="button1"></div>
        <div id="arrowRight"><img src="arrowRight.jpg" class="controll" id="button2"></div>
        <div id="arrowLeft"><img src="arrowLeft.jpg" class="controll" id="button3"></div>
        <div id="arrowDown"><img src="arrowDown.jpg" class="controll" id="button4"></div>
        <div id="stop"><img src="stop.jpg" class="controll" id="button5"></div>
    </div>
<script type="text/javascript">

        document.getElementById('button1').onclick = function(){
           document.getElementById('commands').innerHTML = 'Forward' 
        }
        document.getElementById('button2').onclick = function(){
            document.getElementById('commands').innerHTML = 'Right'
        }
        document.getElementById('button3').onclick = function(){
            document.getElementById('commands').innerHTML = 'Left'
        }
        document.getElementById('button4').onclick = function(){
            document.getElementById('commands').innerHTML = 'Backwards'
        }
        document.getElementById('button5').onclick = function(){
            document.getElementById('commands').innerHTML = 'Stop'
        }

    </script>
</body>

I am currently seeking advice on finding an efficient yet lag-free method to achieve this. Thank you for any input or suggestions you may have for this project.

Answer №1

If you're looking for a straightforward solution, Python's Flask framework is the way to go in the backend. Check out the Flask documentation and this helpful Flask tutorial.

Answer №2

Introducing Pyscript, a cutting-edge project that integrates Python code seamlessly into your HTML document.

To get started, simply insert the following code snippet into your <head> section:

<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>

Next, place these tags within either your <head> or <body> tags: <py-script> Your Python code here </py-script>

Experience the power of integrating Python with your HTML effortlessly!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Which web browsers are compatible with the input attribute "multiple"?

I am currently incorporating this particular plugin, and its file input does not support multiple file selection. To address this issue, I have added the 'multiple' attribute. However, I am curious if there are any browsers or other platforms (su ...

Is it possible for an image to be displayed in another div or table column when I hover my mouse over it?

I am looking to create an image gallery with thumbnails on the left side. When I hover over a thumbnail, I want the full image to be displayed in another section on the page. Can anyone provide me with the correct code or suggest a plugin to achieve this f ...

Adjusting the spacing between a pair of radio buttons within the identical group

Is there a way to adjust the spacing between two horizontal radio buttons? The buttons are part of the same group, and I want to shift the right button ("Clear Selection") further to the right so it aligns with the buttons in another group below. ...

Background image color not displaying correctly

I've been attempting to overlay a transparent color on top of a background image. While the background image is displaying correctly, I'm having trouble getting the color to show up. I noticed that this question has been asked before. I tried im ...

JavaScript error: Function is not defined when using Paper.js

UPDATE the problem has been solved by making the colorChange function global I am attempting to modify the color of the path when the 'Red' button is clicked using the colorChange function. Despite my efforts, I keep getting an error stating tha ...

Modifications made to the process module in one file are not reflected in a different file

It seems that the process module in NodeJS is not global, resulting in changes made to it in one module not reflecting in other modules. To confirm my findings, I wrote a small piece of code. Here is the snippet: server.js import app from "./app.js& ...

Retrieving object key value from an array using Underscore.js

Hey there, I'm facing a challenge where I need to extract the values of wave1 and wave2 from an array using underscore.js. array = [{"id":1,"name":"Monoprix", "pdv":16,"graph":[{"wave1":22,"wave2":11}]} ; I attempted the following: $scope.wave1 = a ...

Exploring the potential of overflow within a container with a percentage-based

I am attempting to design a webpage that fills the entire screen height without scroll bars, yet contains a scrollable container within it. Despite trying various approaches with percentage heights, I have not been successful as the percentages do not beha ...

Issue with Editing the Layout of a Recently Created Page in Django CMS

I am brand new to the world of Django CMS and currently facing an issue that has me stuck. After adding a new module to an existing Django project and creating a new HTML page, I encountered a challenge with the templates configuration in settings.py. TEM ...

Various outcomes were calculated for multiple Vue.js inputs

I am facing an issue with multiple dynamically added search forms on my webpage. Currently, when a user performs a search on one form, all inputs are being searched instead of just the relevant one. Below is the HTML Code for reference: <div class="ro ...

Is it possible to resume CSS animation when the page is first loaded?

I'm looking for a way to ensure that my CSS animations on the elements in my header.php file continue smoothly when navigating to different pages. For example, if I have a 200-second looped animation and navigate to the "about us" page 80 seconds int ...

Modify a field after creation in a Pydantic BaseModel subclass

I have a Pydantic class structured in the following way, where I aim to modify the foo field by executing a replace operation: from typing import List from pydantic import BaseModel class MyModel(BaseModel): foo: List[str] my_object = MyModel(foo=&qu ...

Resolving Anchor Problems in PHP

I'm struggling with a line of code and need some help: echo "<td>"<a href="userdetails.php?".$row[username].">View Details</a></td>"; When I try to create the link on a page, I want it to be in the format userdetails.php?USER ...

Optimizing Query Sets in Django 1.8: Filter Query Sets with Overridden get_query_set() Method in ModelAdmin

exploring a class and a proxy : class ExchangeNeighbor(NeighborModel): class Meta(NeighborModel.Meta): pass ... exchange_type = models.SmallIntegerField(choices = EXCHANGE_TYPE, verbose_name = 'Type') ... class DonationProposal ...

Modifying content on links that are dynamically created

I have some dynamically added link elements that are initially hidden from the page. These links are generated by a third party telerik control, and I need to change the text of these links using jQuery. I have created a rule (selector) that targets the ...

JavaScript transform numbers into array of buffers with a length of 4

I'm looking for a way to insert a numerical value into an array of 4 values [uint32_t] For example 255 should look like [0x00, 0x00, 0x00, 0xFF] I need to transmit this value from a Node.js server to an Arduino board Is there a built-in solution or ...

Tips for utilizing jQuery Ajax data action

I've been trying to understand how to effectively utilize the data parameter in a $.Ajax call. However, I am facing confusion regarding the 'action' part within the data call. Is it meant to trigger an action in a controller? If so, how can ...

Selecting values from req.body dynamically based on database attribute requirements

I am in the process of developing a Node/EJS/Mongo app where users are creating a capability survey and specifying the desired level for each question. The interface for selecting these levels consists of dropdown menus with options like: <select class ...

Deliver SMS and MMS messages to recipients using my business phone numbers

Is there a way to integrate a third-party API with Python to send MMS and SMS messages without being limited to using numbers provided by the platform? I would like to use my own personal phone numbers or a list of numbers with the API for sending SMS and ...

Encountering a Parse Error with Less CSS triggers an error message for unrecognized input specifically related to background properties

I am struggling to identify the issue with my CSS while using the LESS CSS library. After running my site with LESS, I encountered an error. However, upon examination, the CSS appears to be valid. Can someone please point out what could be wrong with my C ...