Google News
logo
Tkinter - Interview Questions
How to make a new folder using askdirectory dialog in Tkinter?
To make a new folder using askdirectory dialog in Tkinter, we can take the following steps :
 
  * Import the required modules. filedialog module is required for askdirectory method. os module is required for makedirs method.
  * Create an instance of tkinter frame.
  * Set the size of the frame using win.geometry method.
  * Define a user-defined method "create_subfolder". Inside the method, call filedialog.askdirectory to select a folder and save the path in a variable, source_path.
  * We can use askdirectory method of filedialog to open a directory. Save the path of the selected directory in a 'path' variable.
  * Then, use os.path.join and makedirs to create a sub-folder inside the parent directory.
  * Create a button to call the create_subfolder method.
Advertisement