2

I’d like to create a restricted folder/ file explorer in Python (I have version 2.7.9, but I don’t mind changing that) for Windows.

Essentially, I want to initially specify the folder to which the code opens. For example, the code should initially open to: C:\Users\myName\Desktop\myDemoFolder (the user must not know this folder simply by looking at the GUI).

The user must be able to browse downwards (deeper into folders) and backwards (but only up to the initial folder to which the code opens). The user must be able to click to open a file (for example: pdf), and the file must automatically open in its default application.

An example of what I’d like is presented in figure 1. (The look of the interface is not important)

Figure 1: What I would like to get

Currently, I am able to get figure 2 using the code presented here:

from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw() 
filename = askopenfilename()
print(filename)

Figure 2: What I currently have

Research has indicated that it is not possible to change the default buttons in Tkinter windows. Is this true? If it can’t be done with Tkinter (and that’s fine), how else can we do it?

I’d happily choose simple, non-Tkinter code (perhaps using wxPython’s wx.GenericDirCtrl()) rather than elaborate Tkinter code, but no restrictive libraries please.

A modular design approach is not needed. I’d rather have simple (functional) code that is shorter than object-oriented code.

Community
  • 1
  • 1
  • as far as I know you can't change tkinter default buttons but you can set the path of initial directory when user opens for e.g: `askopenfilename(initialdir='path/which/you/want/to/set')` and show us what you have tried SO is not a code writing site. – shivsn Jul 05 '16 at 08:03

1 Answers1

0

I was trying to do the same thing when I realized that maybe you could create all the buttons you need and then set the color of the buttons you don't need to your background color using:

button-name.config(bg = "background-color")

Just change the "button-name" to your button's name and set "background-color" to the background color!

Adrian Mole
  • 43,040
  • 110
  • 45
  • 72