Forums

How to use text boxes that can do things in Python?

hoping to use some text box functionality (like JavaScript operations) on here. Ie. create buttons that can be clicked etc to do stuff - but I take it you can't use Tkinter, and I'm not going down the JS route.

So is there another module that can be used?

to start off I just want to be able to 'clear' an HTML text box

for example:

@app.route('/input', methods=['POST'])
def input2():
    h = request.form['texty2']
    i = h
    j = request.form['texty3']
    k = j

    return render_template('input.html', i=i, k=k)

this renders both i and k variables onto the html page (input.html) , but only one at a time after submitting data on html page k = london i = brighton

when london is entered it appears on html page via submit button, however the second variable makes the first disappear, so how to render both at the same time?

I also have this code above that function:

@app.route('/input')
def input1():
    return render_template('input.html')

html:

<html>

    {{ fortnite }}

<br>


<head>Distance Matrix<br><br></head>
Enter two locations to calculate distance<br><br>

<form method="POST">
    <input name="texty2">
    <input type="submit" class="like" value="Enter location 1" /><br><br>


    <input name="texty3">
    <input type="submit" class="like" value="Enter location 2" /><br><br>


</form>

<br>
{{ i }} <br>
{{ k }}
<br>

so are you basically trying to run python in the browser?

there are many tools to do this. skulpt implements a complete Python interpreter in javascript. there is also transcrypt which compiles python to javascript

you like nisa

this seems to do the trick:

@app.route('/input')
def input1():
    return render_template('input.html')


@app.route('/input', methods=['POST'])
def input2():
    j = request.form['texty3']
    k = j
    h = request.form['texty2']
    i = h
    l = k + i
    return render_template('input.html', k=k, i=i, l=l)

I'm basically trying to create js type box functions

I want to have a user input two places, then calculate the distance between them by pressing 'submit'

so far it's like this:

http://madmartin.pythonanywhere.com/input

I'll have a look at those 2 sites, thanks

Nisa has gone now unfortunately

Nisa has gone now unfortunately

congrats

JavaScript really is the best tool for this kind of thing, unfortunately, but if what you want is a form where the user can enter a value in one field, submit it, and then see the value that they already entered in the field where they entered it, you could use your original code with a tweak to the input fields in the HTML template:

<html>

    {{ fortnite }}

<br>


<head>Distance Matrix<br><br></head>
Enter two locations to calculate distance<br><br>

<form method="POST">
    <input name="texty2" value="{{ i }}">
    <input type="submit" class="like" value="Enter location 1" /><br><br>


    <input name="texty3" value="{{ j }}">
    <input type="submit" class="like" value="Enter location 2" /><br><br>


</form>

<br>
{{ i }} <br>
{{ k }}
<br>

ok, cheers

JavaScript really is the best tool for this kind of thing

I loved Giles until he said this

I'm hoping to avoid using JS too much.

anyway, I now have a few towns added, just need to find a way of not having to put them all in manually

I guess a database is possibly the next move?

so far I have this in flask_app.py:

@app.route('/input', methods=['POST'])
def input2():
    j = request.form['texty3']
    k = j

    l = '96 miles'
    m = '87 miles'
    n = '331 miles'
    o = '287 miles'
    p = '162 miles'
    q = '133 miles'

    if k == 'Bath':
        return render_template('input.html', k=k,  l=l)
    elif k == 'Cheltenham':
        return render_template('input.html', k=k,  m=m)
    elif k == 'Edinburgh':
        return render_template('input.html', k=k,  n=n)
    elif k == 'Dublin':
        return render_template('input.html', k=k,  o=o)
    elif k == 'Manchester':
        return render_template('input.html', k=k,  p=p)
    elif k == 'Taunton':
        return render_template('input.html', k=k,  q=q)

    else:
        return render_template('error.html')

Yeah, JS is a terrible and strange language that has weird functionality and sucks at reporting errors.

meme

There are some JavaScript preprocessors such as TypeScript and CoffeeScript which are basically improved versions of JavaScript that compile into normal JS. There's also preprocessors for CSS as well.

I've done some basic JS and may use a bit just to clear text boxes etc..

however, now I want to add more places to the distance finder - do you have a town or place you'd like me to add?

16 Funniest City Names Around The World

You need to make the yellow box more legible; it's greyed out in Safari on iPadOS

some of those are funny! esp. the first one

ok, I'll put in Dull, Scotland

what colour do you suggest for ipad?

just changed text to blue, any better?

Set the background-color to white and color to black

actually, the purpule color you just added is much better

blue*

You should also add Middlefart

ok, cool, I'll leave it that colour then

so blue, with yellowish background looks ok on ipad?

yes

I think I should add a "delete site" button to my site and see how many people try clicking it

could be an interesting way of counting visitors to the site

:)