webpy: how to change the value of a textbox periodically?
Posted: Thu Oct 29, 2015 3:46 pm
Hi,
I use web.py in my code and have to periodically update the value of textboxes.
My questions are:
1.)
How can i achieve to do some other job (like reading data from a sensor), while
the web-server is running ("app.run()")
2.)
What is the correct syntax to change the value of the textboxes?
e.g:
within def GET(): what syntax do I have to use to set the value of the
textbox "temp_now"?
??? form_.id(temp_now).set_value(temp_now) ???
Code: Select all
import web
import RPi.GPIO as GPIO
from web import form
import random
import time
.
.
.
# Defining the buttons. 'id' stands for HTML id of the element.
# #'value' is the value of the button as perceived by Python.
# #'html' is the text displayed in HTML page. 'class_' is HTML class
my_form = form.Form(
form.Button("btn", id="btnR", value="on", html="on", class_="on"),
form.Button("btn", id="btnG", value="off", html="off", class_="off"),
form.Textbox('Temp:', id='temp_now', value="missin g "),
form.Textbox('Max:', id='temp_max', value="missing"),
form.Textbox('Min:', id='temp_min', value="not implemented"),
form.Radio('details', ['Home Page', 'Content', 'Contact Us', 'Sitemap']),
)
# define the task of index page
class index:
# rendering the HTML page
def GET(self):
# return app.root_path()
temp_now = randomTemp()
print (temp_now)
print (" ")
form_ = my_form()
# UPDATE VALUES OF TEXTBOXES HERE
return render.index(form_, "Raspberry Pi B+")
# run
if __name__ == '__main__':
app.run()
I use web.py in my code and have to periodically update the value of textboxes.
My questions are:
1.)
How can i achieve to do some other job (like reading data from a sensor), while
the web-server is running ("app.run()")
2.)
What is the correct syntax to change the value of the textboxes?
e.g:
within def GET(): what syntax do I have to use to set the value of the
textbox "temp_now"?
??? form_.id(temp_now).set_value(temp_now) ???