tkFileDialog.askdirectory root directory ?

R

Ringwraith

Hello!

I have the following problem. I use the tkFileDialog.askdirectory dialog to
allow users of my application to pick some subfolder from 'C:/my_app'
directory. I use initialdir='C:/my_app' option to set 'C:/my_app' as initial
directory. But I want my initial directory to be also a root directory, so
the user cannot pick any directory outside 'C:/my_app' folder. I have no
idea how to do it using standard tkFileDialog.askdirectory. Is that
possible?

Thank you in advance for any hints.

Best wishes,

Niki
 
M

Martin Franklin

Ringwraith said:
Hello!

I have the following problem. I use the tkFileDialog.askdirectory dialog to
allow users of my application to pick some subfolder from 'C:/my_app'
directory. I use initialdir='C:/my_app' option to set 'C:/my_app' as initial
directory. But I want my initial directory to be also a root directory, so
the user cannot pick any directory outside 'C:/my_app' folder. I have no
idea how to do it using standard tkFileDialog.askdirectory. Is that
possible?

Thank you in advance for any hints.

Best wishes,

Niki

Unles there is a speacial windows extra thingy I don't think you could
stop the user selecting a directory not below C:/my_app however you can
at least start the directory selector with that as it's initial
directory like so:


tkFileDialog.askdirectory(initialdir="C:/my_app")


HTH
Martin
 
R

Russell E. Owen

"Ringwraith said:
I have the following problem. I use the tkFileDialog.askdirectory dialog to
allow users of my application to pick some subfolder from 'C:/my_app'
directory. I use initialdir='C:/my_app' option to set 'C:/my_app' as initial
directory. But I want my initial directory to be also a root directory, so
the user cannot pick any directory outside 'C:/my_app' folder. I have no
idea how to do it using standard tkFileDialog.askdirectory. Is that
possible?

Some possible solutions:
- Write your own version that does this, e.g. via bindings that detect
when the user tries to change directory and screens the requested
change. Unfortunately, from a quick look at tkFileDialog, I did not see
any easy way to adapt the existing code; unless I missed something you
may have to pretty much code from scratch.
- Allow the user to select anything, but then test it and reject it if
it doesn't meet your requirements. This is trivial to code, but a pain
for the user.
- See if you can redesign your code to eliminate the requirement.

-- Russell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top