Tkinter askopenfilename dialog hangs on mac

First of all, I am sorry if this isn’t the right place to post this or if it’s my code and not a problem with jupyter/mac.

When I use jupyter (but not spyder) to open a dialog box to select my data file, it always hangs and gives me a pinwheel loading error until I kill python. I don’t have this issue on my windows computer and my laptop runs on High Sierra 10.13.6.

Here is the code I am running, I have a bunch of stuff commented out because I’m trying to make everything work. These lines were commented out when I run the script. The file is loaded successfully and the graph is generated, but the dialog box doesn’t go away. Also, I took a screenshot here.

import numpy as np
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
file = filedialog.askopenfilename()
file_data = np.loadtxt(file, delimiter=’,’)
num_points = 5
x_min, x_max = 0, 4
x_values = np.linspace(x_min, x_max, num_points)
y_values = x_values**2
plt.plot(x_values, y_values)
#plt.set_title(‘HIV Drug Treatment’, fontsize=‘24’)
#ax = plot.gca()
#ax.set_xlabel(‘Time Since Administration (s)’, fontsize=‘12’)
#ax.set_ylabel(‘Concentration of Virus (unitless)’, fontsize=‘12’)

Did you try adding root.update() before file = filedialog.askopenfilename() ?
If that doesn’t work then try root.update() after file = filedialog.askopenfilename() ?
See here.

I added root.update() instead of root.destroy(). The dialog box does not freeze anymore (it actually goes away), but I still cant get the tkinter box to go away. Still it is at least functional and unobtrusive. Thank you.