我已经完成了一个处理一些图像的脚本,最后,它会问你想把文件保存在哪里。我用tkinter(下面的代码(做的。它运行良好,我唯一的问题是:
我有一个与函数destroy
链接的退出按钮,当我单击它时,根目录已关闭,但脚本仍在运行,没有出现错误,我必须手动停止它。如果我使用quit
,脚本会停止,但根窗口会冻结,并且在重新启动python时出现内核错误。我尝试在root.mainloop
之后使用sys.exit()
,但脚本并没有脱离循环。希望你能帮忙,谢谢。
我正在使用Spider,python 3.7.6,Ipython 7.19.0
root = Tk()
root.geometry('200x150')
# function to call when user press
# the save button, a filedialog will
# open and ask to save file
def save():
filename2 = filedialog.asksaveasfile(mode='wb+',defaultextension=".tif", title="Choose filename")
if not filename2:
return
imwrite(filename2, stack, imagej=True)#
# root.destroy()
button_save = Button(root, text = 'Save', command = lambda : save())
button_save.grid(row=1,column=2)
button_exit=Button(root,text='Exit program', command=root.destroy)
button_exit.grid(row=5,column=2)
root.mainloop()
好的,我解决了它,也许它对将来的某个人有帮助。
我定义了一个新的功能来退出如下:
def _quit():
root.quit()
root.destroy()
button_exit=Button(root,text='Exit program', command=_quit)