- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
# 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()
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.
- Calling external programs using SAP connector
- How to open PIL Image in Tkinter on Canvas?
- How to specify where a Tkinter window should open?
- Programs Using Interface Modules
- How to open an Excel Spreadsheet in Treeview widget in Tkinter?
- How to open hidden file using C#?
- How do I open a website in a Tkinter window?
- Connect to external server by using phpMyAdmin
- How to implement Open Closed principle using C#?
- Application Programs vs System Programs
- Python program to Order Tuples using external List
- How to open multiple filenames in Tkinter and add the file names to a list?
- How to open new pseudo-terminal pair using Python?
- How to open a new tab using Selenium WebDriver?
- How to open a new pseudo-terminal pair using Python?