1

I want to embed/put a tkinter gui in a flask app, but the code i made seems not to be rendering/show and gives this error when i run my code:

[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 -

also when i want to run the flask web server it shows 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()
Capt.Pyrite
  • 851
  • 7
  • 24

0 Answers0