Tkinter 导致 Jupyter 内核崩溃?

Coo*_*654 2 python crash tkinter jupyter jupyter-notebook

因此,我第一次开始使用 tkinter (8.6.7),通过 conda 安装到我的一个带有 python 3.5.4 的环境中,由于某些原因,它一直导致我的 jupyter 笔记本崩溃。这是我使用的简单代码,

from tkinter import filedialog
from tkinter import *

root = Tk()
root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
Run Code Online (Sandbox Code Playgroud)

一旦我退出使用 Finder 打开的对话框窗口(我在 Mac 上),我的内核就会崩溃并重新启动,即使我没有选择任何文件并只按取消键。

有谁知道为什么这种情况不断发生?我的环境是最新的,可以使用 numpy,例如,没有问题。

Opp*_*ppy 5

我复制了你的问题。使用 %%python 魔法解决了我的问题。尝试这个:

%%python

from tkinter import filedialog
from tkinter import *

root = Tk()
root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select 
file",filetypes = (("jpeg files","*.jpg"),("all files","*.*"))
Run Code Online (Sandbox Code Playgroud)