Welcome folks today in this blog post we will be opening
external files in python using a gui library called as tkinter. All the source code of the application will be given below.
In order to get started you need to make sure python is installed on your system. And then you need to install
tkinter library using pip command
pip install tkinter
We are using the system() method in the os module to open external
programs in python.
After installing it, now just make a
app.py file and copy paste the following code
# Import Library
from tkinter import *
from tkinter.filedialog import askopenfilename
# Create Object
root = Tk()
# Set geometry
file = askopenfilename()
os.system('"%s"' % file)
Button(root, text ='Open',
command = open_file).pack(side = TOP,
pady = 10)
# Execute Tkinter
Now if you execute your python script
app.py by running the following command
you will see a button inside gui to open external files
Now you can see that if we click this button a new window will appear to select the files to open as shown below.
Now you can see that we have selected the image to open and it has automatically selected the photos app to open the image as shown below.