What could cause an open file dialog window in Tkinter/Python to be really slow to close after the user selects a file?

后端 未结 2 965
暖寄归人
暖寄归人 2021-01-02 00:59

I can do the following in my program to get a simple open file dialog and print the selected file path. Unfortunately it doesn\'t go away right away when the user selects t

相关标签:
2条回答
  • 2021-01-02 01:54

    Exactly the problem I had - sometimes the file dialog would go away after a while, sometimes not. But it always seemed to block a later status windows. Adding the root.update() fixed both problems immediately.

    0 讨论(0)
  • 2021-01-02 01:57

    I was having some trouble with Tkinter dialog boxes. Like you, the dialog just sat there after I had selected a file. I didn't try leaving it for very long, it may have disappeared after 5 minutes as you said your's did. After lots of random experimentation I found that calling root.update() before the askopenfilename() line seemed to fix it.

    For reference, this is the code I was testing with:

    import sys
    from tkinter import *
    from tkinter import filedialog
    
    #instantiate a Tk window
    root = Tk()
    
    #set the title of the window
    root.title('Tk test')
    
    #dunno what this does, fixes askopenfilename if I use it.
    root.update()
    
    print(filedialog.askopenfilename(title='dialogue? surely.'))
    
    0 讨论(0)
提交回复
热议问题