कभी-कभी, एप्लिकेशन बनाते समय, हमें external programs और applications के साथ interact करने की आवश्यकता होती है। System के applications और programs के साथ interact करने के लिए, हमें python में os Module का उपयोग करना होगा।
इस लेख में, हम देखेंगे कि OS module in Python का उपयोग करके external programs के साथ कैसे interact करें और files open करें।
पहले, हम एक function define करेंगे जो filedialog library in Python का उपयोग करके chosen file open करेगा। फिर, हम path print करेंगे और os module का उपयोग करके file open करेंगे।
उदाहरण
# Import the required Libraries
from tkinter import *
from tkinter import filedialog
import os
# Create an instance of tkinter frame
win = Tk()
# Set the geometry for the window or frame
win.geometry("600x400")
# Define a function to open the application
def app():
file = filedialog.askopenfilename()
text.config(text=file)
# Open the program
os.system('"%s"' % file)
# Create a button
Button(win, text='Click to Open a Program', font=('Poppins bold', 10), command=app).pack(pady=20)
# Create a Label after button event
text = Label(win, text="", font=('Poppins bold', 10))
text.pack(pady=20)
# Keep running the window or frame
win.mainloop()
आउटपुट
उपरोक्त code चलाने से निम्न window output के रूप में produce होगी:

अब, button पर क्लिक करें और यह "My Documents" folder खोलेगा जहां से आप एक program open कर सकते हैं।