试图结合烧瓶和guizero

时间:2017-05-06 15:54:27

标签: python-3.x flask raspberry-pi3

所以当我有一个有趣的想法时,我正在尝试烧瓶。如果我可以将guizero与我的服务器结合起来,我可以像我的简单服务器的控制台一样。所以当我偶然发现2个问题时,我就开始工作了。

这是我的代码:

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()

模板index.html只是一个带{{text}}的段落。它确实显示了没有消息"字符串。

现在我遇到了这个代码的2个问题。

1:如果我运行它只启动服务器,但是当我再次运行它时它会使用#34;已经在使用"错误,然后打开gui

2:如果我使用gui,当我按下按钮时网站不会更新,我认为因为gui不会在与服务器相同的脚本实例中运行。如果确实如此,我认为调试功能不适用于脚本中的变量。

如果重要的话,在以太网上的raspi 3B上运行服务器

我对flask和html很新,所以也许我不理解你的答案,但如果你能提供帮助,我会很高兴

0 个答案:

没有答案