1

So i was trying flask when i got an funny idea. If i could combine guizero with my server i could make like a console for my simple server. So i began working when i stumbled over 2 problems.

Here's my code:

from flask import Flask, render_template
from guizero import App, PushButton, Text, TextBox

app = Flask(__name__)
app.debug = True
console = App(title='web server')
text_input = "no message"

def message():
    text_input = textbox.get
    textbox.clear

header = Text(console, text="Web server console", size= 50)
description = Text(console, text="type message here:")
textbox = TextBox(console)
button = PushButton(console, text="send", command=message)

@app.route('/')
def index():
    return render_template('index.html', text= text_input)
@app.route('/next')
def next():
    return render_template('game.html')

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
    app.display()

The template index.html is just simply a paragraph with {{text}}. It does show the "no message" string.

Now i'm experiencing 2 problems with this code.

1: If i run it it only starts the server, but when i run it again it gives the "already in use" error and then opens the gui

2: If i use the gui the website won't update when i push the button, i think because the gui doesnt run in the same instance of the script as the server. And if it does i don't think the debug function works with variables in the script.

running the server on a raspi 3B on ethernet if that is important

i'm very new to flask and html so maybe i won't understand your answer but i'd be glad if you could help

Jelluhtjuh
  • 11
  • 3

1 Answers1

0

I also am new to Flask but I think you have to make a new thread (either for the Flask app or the GUI). This makes sure that both Flask and the GUI can run simultaneously. Now you try to run two loops at the same time and tht doesn't work.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '22 at 14:13