0

My question is similar to Replacing input() portions of a Python program in a GUI. But I need a web UI not desktop UI(tkinter based solution as answered in the link)

2 Answers2

0

You will have to create a webpage with HTML/CSS and create a form in it to get the input. Then, you will have to link the webpage with your backend (flask) to receive the input in python and manipulate as needed. Following a tutorial like this one will help you get started. Or, you can simply search the web for "Form handling in Flask" to find something that suits your needs.

Moosa Saadat
  • 1,159
  • 1
  • 8
  • 20
0

Say you're asking for the user to input their username. You'd do something like this.

HTML

<body>
  <form action="" method="post">
    <input type="text" placeholder="" value="{{ request.form.username }}">
    <input type="submit" value="Submit">
  </form>
</body>

Whatever you want to call your variable, you put after request.form

In your program (where you import flask), also import request from flask like so:

from flask import request

Under your route's function, check if the request's method is POST and assign your form variable:

def index():
  if request.method == "POST":
    foo = request.form["username"]
  return render_template("index.html")

So when the user clicks the submit button, foo will be whatever they put in the text box.

You can see more at https://flask.palletsprojects.com/en/1.1.x/quickstart/#accessing-request-data