我已经创建了3个脚本,现在我正在Tkinter中创建一个简单的前端菜单。当我单独使用脚本时,它们会按预期工作并退出,因此我知道它们没有问题。问题一定出在我的菜单上(如下)。
从菜单中,选择一个工具,该工具将调用另一个脚本并运行它。脚本只是挂起,一直等到我按键盘上的Enter键。当我按Enter键时,脚本然后退出。如何使其自动退出,而不是必须按Enter键?
提前致谢。
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()
明确等待子流程将解决您的问题。(使用subprocess.Popen.wait
)
def callDuff():
print "Call back works"
proc = subprocess.Popen("python duff.duplicateFileFinder\duff.py", shell=True)
#^^^^^^
kill_window()
proc.wait() # <-----
顺便说一句,root.withdraw()
不终止该程序。它只是隐藏主窗口。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句