2

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.

  • Seems to be working for me.... Update your answer to include the Python version and Computer your using + OS... – SF12 Study Aug 24 '19 at 03:25

1 Answers1

0

I have encountered the same issue when running some code that would open, modify, and overwrite an image. Everything worked as expected until suddenly askopenfilename() started Not Responding and not opening the file dialog window.

I have attempted changing the initial directory of askopenfilename() and calling the method from a separate file and the command line without success.

One of my open windows was a directory (not the same as I was working with) on which file thumbnails failed to load and files could not be opened. Upon closing the window, the screen 'reloaded,' certain programs opened (such as sticky notes, which was previously closed but which typically opens upon restarting), and the method resumed normal functionality.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140