I'm currently developing a small tool thats parsing some input files given by the user in a Tkinter GUI. It then starts a Dash-Server to visualize the parsed data.
The problem that I'm facing right now is that the call of dash_app.run_server()
seems to reexecute the mainloop
of the GUI so that a new window is opened and the Dash-Server crashes. But that only happens once. If I start the process again from the new window, the server properly starts and no new window appears.
I also tried to start Dash inside a new thread but it seems like it needs to run in the main-thread so that is no option.
Are there any suggestions on how to fix this issue?
Minimal Example:
from tkinter import *
import dash
import dash_html_components as html
class App(Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Button(self, text="Start",
command=self.start).pack()
def start(self):
self.destroy()
plotter = Plotter()
class Plotter():
def __init__(self):
self.__run_dash()
def __run_dash(self):
dash_app = dash.Dash(__name__, prevent_initial_callbacks=True)
dash_app.layout = html.H1("Test")
dash_app.run_server(debug=True)
def main():
app = App()
app.mainloop()
if __name__ == "__main__":
main()