I would like to modify the tkFileDialog to include a Checkbutton for "open this file after saving."
The boolean value of this Checkbutton would determine whether os.startfile()
gets called on the file name returned from the dialog, or not.
Example: how could I set the variable openMeNow
in:
import tkinter as tk
from os import path, startfile
import pandas as pd
def getOutputFileName(initDir,title="Save Output as",initFile="the_output",defaultExt=''):
root = tk.Tk()
root.lift()
root.attributes("-topmost", True)
root.withdraw()
fOut = tk.filedialog.asksaveasfilename(title=title,
initialdir=initDir,
initialfile=initFile,
defaultextension=defaultExt)
return fOut
outExcel = path.normpath( getOutputFileName(
title="Save Workbook as",
initDir='~/Documents',
initFile='the_workbook.xlsx',
defaultExt='.xlsx'
) )
# do some stuff that returns some results
results = pd.DataFrame({'a':[1,2],'b':[10,100],'c':[0,50]})
xlWriter = pd.ExcelWriter(outExcel, engine='xlsxwriter')
results.to_excel(xlWriter, sheet_name = 'The Results', index=False)
xlWriter.save()
if openMeNow: startfile(outExcel)
The question is sort of similar to this one, with the difference being that I'm trying to modify the filedialog
class rather than add another dialog box.