askopenfilename - A tkFileDialog problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Traclo
    New Member
    • Oct 2007
    • 12

    askopenfilename - A tkFileDialog problem

    Hello all! I have a problem concerning tkFileDialog. When I use the the askopenfilename command to open a text file it opens a tkinter window (apart from the file browsing window) which refuses to close once I've selected and opened the file. It just stays there and when clicked on says not responding.

    I am using Vista, writing this file in Wing, and have the latest version of python

    My code for this interaction goes like this:
    Code:
    import tkFileDialog
    file = tkFileDialog.askopenfile()
    This opens the file browsing window fine, but as I said leaves an unresponding tkinter window open when I've selected the file. If I ignore the window and return to the shell the file variable has the text file open fine, but that tkinter window is distracting. And if I manually close it by killing the process, then the shell no longer works.

    Anyone with a quick fix?

    P.S.
    I have to use tkFileDialog, because it is for my university assignment
  • drewski526
    New Member
    • Jan 2008
    • 7

    #2
    hi,
    you're only problem is that a root window is automatically created when you call tkFileDialog.as kopenfile().
    for instance, try this:

    Code:
    from Tkinter import *
    import tkFileDialog
    root = Tk()
    root.withdraw()
    file = tkFileDialog.askopenfile(parent=root)
    file_read = file.read()
    the last line is just there to read the file.

    Comment

    • Traclo
      New Member
      • Oct 2007
      • 12

      #3
      Thanks that worked perfect!

      Comment

      Working...