Tkinter crashes Jupyter kernel?

2020-03-30 04:38发布

So I'm starting out with tkinter (8.6.7) for the first time, installed via conda unto one of my environments with python 3.5.4 on it, and for some reasons it just keeps crashing my jupyter notebook. This is the simple code I use,

from tkinter import filedialog
from tkinter import *

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

and as soon as I exit the dialog window that gets opened using Finder (I'm on a mac), my kernel crashes and restarts, even if I pick no files and just press cancel.

Does anyone have any idea why this keeps happening? My environment is up to date, and can use numpy, for ex., with no problems.

1条回答
▲ chillily
2楼-- · 2020-03-30 05:08

I replicated your problem. Using the %%python magic solved if for me. Try this:

%%python

from tkinter import filedialog
from tkinter import *

root = Tk()
root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select 
file",filetypes = (("jpeg files","*.jpg"),("all files","*.*"))
查看更多
登录 后发表回答