Python Tkinter Script to Open External Files and Programs Applications Using System Method in OS Module Full Project For Beginners

Python Tkinter Script to Open External Files and Programs Applications Using System Method in OS Module Full Project For Beginners

 

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.

 

 

 

Get Started

 

 

 

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

 

 

Method Used

 

 

 

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

 

 

app.py

 

 

# Import Library 
from tkinter import *
import os 
from tkinter.filedialog import askopenfilename  
  
# Create Object  
root = Tk()  
  
# Set geometry 
root.geometry('200x200')  
  
def open_file():  
    file = askopenfilename() 
    os.system('"%s"' % file) 
  
Button(root, text ='Open',  
       command = open_file).pack(side = TOP,  
                                 pady = 10)  
  
# Execute Tkinter 
root.mainloop()

 

See also  Python 3 Script to Find Prime Numbers From a Given Range of Numbers Full Tutorial For Beginners

 

Now if you execute your python script app.py by running the following command

 

python app.py

 

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.

 

 

 

 

 

Leave a Reply