Question

I've created 3 scripts and now i'm creating a simple front-end menu in Tkinter. When I use the scripts individually, they work and exit as they should, so I know there is no problem with them. The problem must be with my menu (below).

From the menu, I select one of the tools, which calls another script and runs it. The script just hangs and waits until I hit enter on the keyboard. When I hit enter, the script then exits. How can I make it exit automatically rather than me having to hit enter?

Thanks in advance.

from Tkinter import *
import Tkinter
import subprocess

root = Tkinter.Tk()
root.title("SimonsSoftware, 2014")
root.geometry('255x200+200+200')
text = Text(root)
text.insert(INSERT, "Please select which tool\nyou wish to use...")


def close_window():
    root.withdraw()

def kill_window():
    root.destroy()

def callDuff():
    print "Call back works"
    subprocess.Popen("python duff.duplicateFileFinder\duff.py", shell=True)
    kill_window()

def callFibs():
    print "Call back works"
    subprocess.Popen("python fibs.FileInvestigationBiteSize\\fibs.py", shell=True)
    close_window()

def callShift():
    print "Call back works"
    subprocess.Popen("python shift.SimonsHashInfoFinderTool\shift.py", shell=True)
    close_window()


buttonOne = Tkinter.Button(root, text ="DUFF", relief=FLAT, command=callDuff)
buttonTwo = Tkinter.Button(root, text ="FIBS", relief=FLAT, command=callFibs)
buttonThree = Tkinter.Button(root, text ="SHIFT", relief=FLAT, command=callShift)

buttonOne.pack()
buttonTwo.pack()
buttonThree.pack()
text.pack()
root.mainloop()
Was it helpful?

Solution

Explicitly waiting the subprocess will solve your problem. (using subprocess.Popen.wait)

def callDuff():
    print "Call back works"
    proc = subprocess.Popen("python duff.duplicateFileFinder\duff.py", shell=True)
    #^^^^^^
    kill_window()
    proc.wait() # <-----

BTW, root.withdraw() does not terminate the program. It just hide the main window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top