ipython/jupyter的传统知识问题

ipython/jupyter的传统知识问题,python,tkinter,jupyter-notebook,ipython,tk,Python,Tkinter,Jupyter Notebook,Ipython,Tk,我正试图编写一个从ipython/jupyter笔记本启动的gui,但在使用笔记本中的tkinter时遇到了麻烦,尤其是在让TKGUI窗口优雅地关闭时。关于如何从jupyter创建/启动tkinter gui,然后关闭它而不杀死ipython内核,最佳实践是什么 这是我第一次尝试使用tkinter。我发现了很多关于如何在较旧的ipython版本(例如,ipython 3.2)中实现这一点的详细信息,但对于较新的版本(我使用的是ipython 6.5和Python 3.7.1)则没有这么多 以下是

我正试图编写一个从ipython/jupyter笔记本启动的gui,但在使用笔记本中的tkinter时遇到了麻烦,尤其是在让TKGUI窗口优雅地关闭时。关于如何从jupyter创建/启动tkinter gui,然后关闭它而不杀死ipython内核,最佳实践是什么

这是我第一次尝试使用tkinter。我发现了很多关于如何在较旧的ipython版本(例如,ipython 3.2)中实现这一点的详细信息,但对于较新的版本(我使用的是ipython 6.5和Python 3.7.1)则没有这么多

以下是我尝试过的一个例子:

%gui tk

class MyApp:

    def __init__(self, root):
        frame = tk.Frame(root)
        frame.pack()

        self.button = tk.Button(frame, text="Hello", command=self.hello_world)
        self.button.pack(side=tk.LEFT)

        self.quitbutton = tk.Button(frame, text="QUIT", fg="red", command=root.destroy)
        self.quitbutton.pack(side=tk.RIGHT)

    def hello_world(self):
        print("Hello World!")

root = tk.Tk()

app = MyApp(root)

对我来说,在我尝试关闭tkinter窗口之前,这一切都很正常:按下“退出”按钮或手动关闭窗口都会导致我的mac dock中的内核或剩余的“python”应用程序被杀死,除非我强制退出它(这也会杀死ipython内核)。

你忘了粘贴
root.mainloop()
在您的脚本末尾,或者您的代码中实际上没有它?据我所知,您现在不必在iPython中这样做。您是否尝试过使用
root.quit()
?是的,我尝试过;同样的结果我也有同样的问题。你找到解决办法了吗?