首页 > 解决方案 > 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()

标签: flasktkinterembed

解决方案


推荐阅读