- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to open External Programs using Tkinter?
Sometimes, while creating an application, we need to interact with external programs and applications. In order to interact with the system's applications and programs, we have to use os Module in python.
In this article, we will see how we can interact with external programs and open files using the OS module in Python.
First, we will define a function that will open the chosen file using the filedialog library in Python. Then, we will print the path and open the file using the os module.
Example
# 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()
Output
Running the above code will produce the following window as the output −
Now, click the button and it will open the “My Documents” folder from where you can open a program.
- Related Articles
- Calling external programs using SAP connector
- How to specify where a Tkinter window should open?
- How to open PIL Image in Tkinter on Canvas?
- How to open an Excel Spreadsheet in Treeview widget in Tkinter?
- How do I open a website in a Tkinter window?
- Programs Using Interface Modules
- How to open hidden file using C#?
- How to open a webcam using JavaScript?
- How to load external website into an using jQuery?
- How to load external HTML into a using jQuery?
- How to open multiple filenames in Tkinter and add the file names to a list?
- How to implement Open Closed principle using C#?
- Connect to external server by using phpMyAdmin
- How to open new pseudo-terminal pair using Python?
- How to open a new tab using Selenium WebDriver?

Advertisements