Skip to content
Related Articles

Related Articles

How to open External Programs using Tkinter?
  • Last Updated : 24 Jan, 2021

Prerequisite: Tkinter, os

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications.  In this article, we will learn how to open an external program using Tkinter. Here we will use the system() method in the os module.

Approach:

  • First, we will import the required library
  • Then we create an object, which will ask for a file that you want to open
  • To open that file we will use the system() method from the os Module.

Syntax:

os.system(‘”%s”‘ % File Path)



Below is the Implementation:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :