I'm developing a program with Python and tkinter that begins with the user adding a text file from their directory. I had built a GUI with tkinter that provided a button to be pressed and a popup window for them to select their file--it was working fine, and then suddenly when I tried to run it it would begin "Not Responding" when I pressed the button meant to launch the popup window.
I am running Python 3.7.3 on Windows 10 in Jupyter notebooks; the tkinter version is 8.6. I have 8 GB of RAM but I'm not using more than 80% of it.
I've tried looking at some similar Stack Overflow questions like the ones here and here:
windows thinks tkinter is not responding
Python tkinter askopenfilename not responding
Trying askopenfilenames() didn't work; neither did adding root.update() or %gui tk.
Here is the code I'm working with:
import tkinter as tk
from tkinter import *
from tkinter import messagebox
from tkinter.filedialog import *
root = Tk()
topFrame=Frame(root)
topFrame.pack()
middleFrame=Frame(root, width=200, height=250,
highlightbackground="yellow",
highlightthickness=3,
borderwidth=2,
relief=RAISED)
middleFrame.pack()
bottomFrame=Frame(root)
bottomFrame.pack()
ourdirectory=[]
def load1():
f1 = askopenfilename(filetypes=(('TXT files','*.txt'), ('All files', '*.*')))
ourdirectory.append(f1)
mylab = Label(topFrame, text="Hello and welcome!")
mylab.pack()
button = Button(bottomFrame, text="Add File", command=load1)
button.grid(row=5, sticky=W)
root.mainloop()
When the "Add File" button is pressed, I expected the program to launch a popup window where the user can navigate in the file directory. Instead, the title text just fades and it doesn't respond--and clicking on the window causes it to announce that it's stopped responding. (This also consistently causes the Jupyter kernel to die.) Still, when I run the code but close the main window without pressing the "File Add" button, it closes fine and nothing freezes or breaks.