I've decided to mess around with Tkinter and import os a bit. I'm running ubuntu 8.10, if that helps any.

Here is what my program was supposed to do:
have two simple buttons, one labeled 'on' and one labeled 'off'. I wanted the on button to launch nautilus and the off button to quit the program and therefore close nautilus, just as it would if I launched nautilus from the terminal.

What it is actually doing:
As soon as i run the program, nautilus launches, and my window with the buttons don't pop up until after I have closed nautilus. Why is this?

Here is my code:

from Tkinter import *       
import os
class Application(Frame):              
     def __init__(self, master=None):
        Frame.__init__(self, master)   

     def createWidgets(self):
        self.onButton = Button ( self, text="on",
            command=os.system('nautilus' ))        
        self.onButton.grid(row=0, column=0)         
        self.offButton = Button ( self, text="off",
            command=self.quit )
        self.offButton.grid(row=0, column=1)

app = Application()                    
app.master.title("My Application") 

Thanks in advance for your help!

8 Years
Discussion Span
Last Post by Gribouillis

It's because os.system waits that the subprocess is finished. You should not use os.system anymore in python. Use the subprocess module

import subprocess
child_process = subprocess.Popen("nautilus", shell=True)

This won't wait for the subprocess. See the documentation of the subprocess module for more complex usage.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.