flask - 2021-02-16 10:43:57,123 应用程序中的错误:/ GET 异常?
问题描述
我想在烧瓶应用程序中嵌入/放置一个 tkinter gui,但是我制作的代码似乎没有呈现/显示,并且在我运行我的代码时给出了这个错误:
[2021-02-16 10:43:57,123] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\User\untitled0.py", line 14, in my_app
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 2369, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 2299, in __init__
(widgetName, self._w) + extra + self._options(cnf))
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1326, in _options
v = self._register(v)
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1372, in _register
self.tk.createcommand(name, f)
RuntimeError: main thread is not in main loop
127.0.0.1 - - [16/Feb/2021 10:43:57] "GET / HTTP/1.1" 500 -
当我想运行它显示的烧瓶网络服务器时Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
from flask import Flask
from webbrowser import open
app = Flask(__name__)
root = Tk()
root.title("Tkinter")
@app.route('/')
def my_app():
def click():
l = Label(root, text = "You Clicked!").pack()
b = Button(root, text = "Click Me!", command = click).pack()
return(root)
if __name__ == '__main__':
open('http://127.0.0.1:5000/')
app.run()
#root.mainloop()
解决方案
推荐阅读
- wpf - 设置 TabItem 标题在单击和未单击选项卡时的前景颜色
- python - 使用 BeautifulSoup 抓取 Cronometer.com 时遇到问题
- php - find() 没有得到现有的行
- gitlab-ci - 使用 gitlab CI 检查编码风格
- mysql - 如何美化MySQL中JSON_ARRAYAGG/JSON_OBJECT的SQL查询?
- wpf - 如何使用 SQLite 数据库部署 WPF 应用程序?
- angular - ngx-translate - 有没有办法在不设置根语言的情况下使用翻译文件?
- c++ - 在 C++ 中使用 Cin 关键字作为变量名
- python - 如何在 vscode jupyter notebook 中使用创建的 python 虚拟环境
- javascript - 如何在reactjs中一次只检查一个复选框?