python - 将 Plotly-Dash 与 Tkinter GUI 相结合 - Dash 强制再次执行 Tk-mainloop
问题描述
我目前正在开发一个小工具,用于解析用户在 Tkinter GUI 中提供的一些输入文件。然后它启动一个 Dash-Server 来可视化解析的数据。
我现在面临的问题是调用dash_app.run_server()
似乎重新执行mainloop
了 GUI,以便打开一个新窗口并且 Dash-Server 崩溃。但这只会发生一次。如果我从新窗口再次启动该过程,服务器会正确启动并且不会出现新窗口。
我也尝试在一个新线程中启动 Dash,但它似乎需要在主线程中运行,所以这是没有选择的。
关于如何解决这个问题有什么建议吗?
最小的例子:
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()
解决方案
推荐阅读
- delphi - 找不到 Arduino AT-Tiny
- android - 在 Ionic 中禁用黑暗主题
- android - 无法刷新firebase IdToken
- python - 关于 LSTM 的 3D 输入形状的快速问题
- angular - 如何使我的 ngDropdown 菜单在悬停而不是单击时工作?
- flutter - 在 Flutter 中:是否可以使用 Future
用作另一个小部件中的属性? - java - 如何自动装配服务,进而在 Junit 中自动装配另一个服务
- r - 如何在 lme4 中获取收敛错误消息或最大梯度
- azure - 为什么赛普拉斯和 Azure DevOps 的测试自动化只能部分成功?
- python - 如何让物体不断向上移动