Hello!

As the title suggests I need some help regarding an "open directory" dialog box.

I tried this code but every time I run the module it appears a blank window in the back of the dialog box and normally after I select the directory it should disappear but it still remains in the background and only if I close it manually it stops. What`s the problem with this? How can I fix it or how can I replace this code with something else? (p.s : I`m still a beginner. A also used easygui for some of the needs)

import Tkinter, tkFileDialog

root = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')

Recommended Answers

All 5 Replies

Problem solved!

catcit,
I'm having the same problem. Can you please post your solution. Thanks a bunch.

Here`s the code with the problem.

import Tkinter, tkFileDialog

root = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')

and here`s the code with the problem solved

import Tkinter, tkFileDialog

root = Tkinter.Tk()
root.withdraw()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')

I used

root.withdraw

in order to get rid of the root from tkinter. If you want to find out more about it google it.

Ok catcit, thank you for the help.

Even simpler, for your console programs you can just use ...

import tkFileDialog

dirname = tkFileDialog.askdirectory(initialdir="/",  title='Please select a directory')

# test
print dirname
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.