Skip to content
Advertisement

How to open new bash terminal using Python

I am trying to open a new terminal window in Tkinter application. I’ve used os.system(“/bin/bash”) but it works in current bash only. Which stops runnning code and causes application freeze. I want to open new Terminal. How to do that? gedit like programs work fine without disturbing current apllication.

def openterm():
    os.system("/bin/bash")
def opengedit():
          os.system("/usr/bin/gedit")
menu = tk.Menu(root)
root.config(menu=menu)
subMenu = tk.Menu(menu)
menu.add_cascade(label="Tools", menu=subMenu)
subMenu.add_command(label="Open Terminal", command=openterm)
subMenu.add_command(label="Open Gedit", command=opengedit)      

Advertisement

Answer

Try this:

# Tested on Ubuntu 14.04.3 LTS
os.system("x-terminal-emulator -e /bin/bash")
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement