TechieYan Technologies

Create a File Manager in Python using Tkinter

Abstract

Creating a file manager is a smooth mission. So, let’s head over to constructing a document supervisor. That is a pretty clean utility. To make it more interactive and thrilling, we are able to use Tkinter in conjunction with Python.

Libraries:

  • Tkinter: It presents wide APIs for GUI functionalities.
  • Shutil: This creates a file manager module that gives some excessive-degree operations on documents and collections of files.
  • Os: utility module for OS interplay in applications.
  • Easygui:  It permits us to choose any record from the machine
  • Filedialog: This library is used for folder choice
  • Imageio: Used to read the file which is selected by using report field the use of a route
File Manager using Python

Code Description & Execution

Program Methodology

Any document supervisor has numerous features. Today, we will provide each viable characteristic to our file manager. Hence, every button may have certain features to exhibit.

Opening a file box :

file manager program

 The above code opens the file field, i.e the pop-up           container to choose the report from the device, which opens whenever you run the code. Fileopenbox() is the approach in easyGUI module which returns the route of the selected report as a string.We can call this feature every time we need to pick any document.

Copying a file

Copying a file when copy a file button is clicked .

file manager code

The above code calls open_window() feature and stores the back path of file chosen in variable “source1”. Variable “vacation spot 1” stores the cope with of the folder lower back with the aid of askdirectory() feature in filedialog module.Shutil.Copy(source1, destination1) copies a record gift at source1 to destination1 cope with. As a result, it opens a popup message container using mb.Showinfo(‘affirmation’, “file Copied !”).

Deleting a file

Deleting a file when Delete a file button is clicked.

File Manager using Python code

The above code calls open_window() function and shops the back course of document selected in variable “string”. If a report is selected os.Do away with(string) feature deletes the file. In any other case, it opens a popup message field the use of mb.Showinfo(‘affirmation’, “file not found!”).

Renaming a file

Renaming a file when Rename a file button is clicked

File Manager using Python renaming code

The above code calls open_window() characteristic and stores the lower back direction of document selected in variable “chosenFile”. Then, variable path1 is used to shop the direction of listing of the file chosen. Os.Course.Splitext() splits the path into root and extensions. As we rename the record, we preserve the equal extension however need to control handiest the call of the file stated inside the root component.

Moving a file

Moving a file when Move a file button is clicked

File Manager using Python coding moving

The above code calls open_window() characteristic and shops the returned path of record selected in variable “source”. And, the variable “destination” stores the deal with of destination folder cope with using filedialog.Askdirectory().

If supply and destination are the equal, it opens a pop up container saying “source and vacation spot is equal”. Else, the file is moved and opens a popup message field the use of mb.Showinfo(‘confirmation’, “record Moved !”).

Building File Manager UI using Tkinter

Building File Manager UI using Tkinter

The above code is used to create a tkinter UI.  Root=TK() is used to make a window. We use canvas() to create a canvas, and an picture is carried out within the history of our window using ImageTk.

Tkinter has two kinds of format managers, grid and p.C.. For format simplicity, we use a grid layout supervisor. Definitely, the usage of grid, we place every button in a single column.

Label() is used to vicinity text label in the root window, with defined font, font size, and shade. Row and column also are targeted at the cease.

Button() characteristic located in root window with textual content particular as textual content=”..” . The subsequent parameter, “command” specifies the characteristic which receives accomplished on every occasion a button is clicked. Please note, the characteristic is exact without brackets within the assertion. Much like label, in each grid widget, we are able to specify row and column. To area the buttons one under the alternative, we specify the same column wide variety, however change the row consistent with our want.

How to Execute?

Note: Make sure you have added path while installing the software’s.

http://techieyantechnologies.com/2022/07/how-to-install-anaconda/

http://techieyantechnologies.com/2022/06/get-started-with-creating-new-environment-in-anaconda-configuring-jupyter-notebook-and-installing-libraries-using-requirements-txt-2/

  1. Install the prerequisites/software’s required to execute the code from reading the above blog which is provided in the link above.
  2. Press windows key and type in anaconda prompt a terminal opens up.
  3. Go to the directory where your requirement.txt file is present, not just requirement.txt, if you want to execute any .py or .ipynb files, you need to go to that specific folder or path, where they are saved.
  4. <<directory of your file:>>. E.g., If my file is in d drive, then.
  5. Type d:
  1. cd d:\License-Plate-Recognition-main    #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
File Manager using Python execution code

          7. If your project is in c drive, you can ignore step 4 and go with step 5

          8. Run pip install -r requirements.txt or conda install requirements.txt (Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.), example: pip install “module_name”.

Results

File Manager using Python result

Issues Faced

  1. We might face an issue while installing specific libraries, in this case, you might need to install the libraires manually. Example: pip install “module_name/library” i.e., pip install pandas
  2. Make sure you have the latest or specific version of python, since sometimes it might cause version mismatch.

Click Here To Download This Code And Associated File.

 

+91 7075575787