本文整理汇总了Python中tkinter.filedialog.asksaveasfile函数的典型用法代码示例。如果您正苦于以下问题:Python asksaveasfile函数的具体用法?Python asksaveasfile怎么用?Python asksaveasfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了asksaveasfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Run
def Run():
m = input('Please select a month, format mm: ')
y = input('Please select a year, format yyyy: ')
comment_option = input('Would you like MedTech Comment emails to be included? Y/N: ')
yes_var = ['Yes', 'YES', 'y', 'Y']
no_var = ['No', 'NO', 'n', 'N']
facility_file = open('facilityList.txt', 'r')
incident_file = askopenfile(mode='r', initialdir="C:/Documents and Settings/medinc.LGBS/Desktop", title='Please select an incident file!')
d = get_facilities(facility_file)
incident_list = populate_incident_list(incident_file)
mincident_list = list(filter(lambda x: find_date_submitted(x)[0:2] == m, incident_list))
myincident_list = list(filter(lambda x: find_date_submitted(x)[6:10] == y, mincident_list))
if comment_option in yes_var:
final_list = [('\t' * 15) + d[find_facility_name(incident)] + '\n' + incident for incident in myincident_list]
if comment_option in no_var:
final_list = [('\t' * 15) + d[find_facility_name(incident)] + '\n' + incident for incident in myincident_list if boolComments(incident) == False]
final_list.sort(key=lambda i: (i[15:18], find_DS_forSort(i)))
date_of_incident_before_m = [alert for alert in final_list if find_date_of_incident(alert)[0:2] != m]
new_final_list = list(filter(lambda alert: find_date_of_incident(alert)[0:2] == m, final_list))
final_file = asksaveasfile(mode='w', defaultextension=".html", filetypes=(("HTML file", "*.html"),("All Files", "*.*")),
initialdir="C:/Documents and Settings/medinc.LGBS/Desktop",
title='Please choose a name for the file with this month\'s DOIs!')
prior_file = asksaveasfile(mode='w', defaultextension=".html", filetypes=(("HTML file", "*.html"),("All Files", "*.*")),
initialdir="C:/Documents and Settings/medinc.LGBS/Desktop",
title='Please choose a name for the file with prior month\'s DOIs!')
html_styling = ('<html>' + '<head>' + '<style>' + 'hr { page-break-before: always;}' + '''pre {
white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap;
word-wrap: break-word;}''' + '</style>' + '</head>' + '<body>')
final_file.write(html_styling)
for alert in new_final_list:
final_file.write('<pre>' + '<font size= "4" face= "Ariel">' +
cgi.escape(alert) + '</font>' + '</pre>' + '<hr>')
final_file.write('</body>' + '</html>')
final_file.close()
prior_file.write(html_styling)
for alert in date_of_incident_before_m:
prior_file.write('<pre>' + '<font size= "4" face= "Ariel">' +
cgi.escape(alert) + '</font>' + '</pre>' + '<hr>')
prior_file.write('</body>' + '</html>')
prior_file.close()
print('Sorting complete! Please open html files to see results.')
示例2: write_dep
def write_dep(self, Z, fname = None, grid_fname = None):
if not fname:
fname = filedialog.asksaveasfile()
else:
fname = fname
if not grid_fname:
if np.ndim(Z) == 1:
m = np.shape(Z)[0]
n = 1
else:
m = np.shape(Z)[0]
n = np.shape(Z)[1]
else:
grid_fname = grid_fname
grid = grd.grd()
grid.read_grd(fname = grid_fname)
m = grid.m
n = grid.n
Z = np.array([np.append(i,-999.) for i in Z])
Z = np.insert(Z, -1, np.ones(np.shape(Z[0]))*-999.)
Z = Z.reshape((m+1, n+1))
np.savetxt(fname, Z, delimiter = '\t', fmt = '%.3f')
print('saved depth file: %s' %os.path.basename(fname))
self.read_dep(fname)
示例3: note_save_as
def note_save_as(self, event = None):
f = filedialog.asksaveasfile(mode='w', defaultextension=".txt") # opens file save dialog
if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
return
text_to_save = str(self.textbox.get(1.0, tk.END))
f.write(text_to_save)
f.close()
示例4: save_as
def save_as():
file = asksaveasfile(defaultextension='.txt')
data = text_area.get(0.0, END)
try:
file.write(data.rstrip())
except:
tkinter.messagebox.showinfo("Cancel", "File Not Saved!")
示例5: save_command
def save_command():
file = filedialog.asksaveasfile(mode='w')
if file != None:
# slice off the last character from get, as an extra return is added
data = textPad.get('1.0', END+'-1c')
file.write(data)
file.close()
示例6: save_input
def save_input():
file2save = filedialog.asksaveasfile(mode = 'w', defaultextension = ".txt")
if file2save is None:
return
inputtext = str(textfield.get("1.0", END))
file2save.write(inputtext)
file2save.close()
示例7: saveAs
def saveAs():
f = asksaveasfile(mode='w',defaultextension='.txt')
t = text.get(0.0,END)
try:
f.write(t.rstrip())
except:
showerror(title="Error",message="File save fail...")
示例8: saveAs
def saveAs():
f = filedialog.asksaveasfile(mode='w', defaultextension='.txt')
t = text.get(0.0, END)
try:
f.write(t.rstrip())
except:
showError(title="Ooops!", message="Unable to save file.")
示例9: text_save
def text_save():
f = filedialog.asksaveasfile(mode='w', defaultextension=".txt")
if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
return
text2save = """<html><body> """ + body + """ </body></html>"""
f.write(text2save)
f.close()
示例10: predict_test
def predict_test(self,toFile=False):
#Check that the testSet actually exists!
if len(self.testSet)>0:
#check that the test set contains the same number of levels as the train set
if sorted(self.targetLevels) == sorted(np.unique(self.encodedTargetTest)):
#testResults contain predictions of the test set predictors
testResults=self.predict_class(self.testPredictors)
#Accuracy is the number of predictions that match the actual values divided by the number of datapoints in the test set
accuracy=sum(list(map(lambda x: x[0]==x[1],zip(testResults,self.encodedTargetTest))))/len(testResults)
print('\nTest Accuracy','%s'% float('%.4g'%accuracy))
if toFile:
#simple GUI is convenient to use
from tkinter.filedialog import asksaveasfile
writelocation=asksaveasfile(mode='w+',defaultextension='.txt')
writelocation.write('Predicted | Actual \n')
#zip predicted an actual into tuples
pairedActualPredicted=zip(*[list(testResults),list(self.encodedTargetTest)])
for row in pairedActualPredicted:
#write each tuple to the file
writelocation.write('\n'+str(row))
if row[0]!=row[1]:
#Note any incorrect predictions
writelocation.write(' * incorrect prediction')
writelocation.close()
return accuracy
示例11: save
def save(self):
from tkinter import Tk
from tkinter.filedialog import asksaveasfile
Tk().withdraw()
simFile = None
try:
simFile = asksaveasfile(mode="wb", initialfile='untitled', defaultextension='sim',
filetypes=[("Newton's Laboratory Simulation File", ".sim")])
finally:
if simFile is None:
return
data = (self.bodies, self.constraints)
for group in data:
for obj in group:
obj.simulation = None
pickle.dump(data, simFile, pickle.HIGHEST_PROTOCOL)
simFile.close()
for d in data:
for x in d:
print(x.__dict__)
for group in data:
for obj in group:
obj.simulation = self
self.planet = self.bodies[0]
示例12: mergeFiles
def mergeFiles():
pdfFile = []
reader = []
writer = PyPDF2.PdfFileWriter()
mylistboxProgress.delete(0, tk.END)
if mylistbox.size() > 1:
for i in range(0, len(fileName)):
#print(reader[i])
pdfFile.append(open(fileName[i], 'rb'))
reader.append(PyPDF2.PdfFileReader(pdfFile[i]))
mylistboxProgress.insert(i, extractName(fileName[i]+" - Progress: " + str(((i+1)/len(fileName))*100)+" %"))
for pageNum in range(reader[i].numPages):
page = reader[i].getPage(pageNum)
writer.addPage(page)
#pdfFile[i].close()
outputName = filedialog.asksaveasfile(title="Save As...", mode='a', defaultextension=".pdf", filetypes =[("Portable Document Format","*.pdf")])
if outputName:
outputFile = open(outputName.name, 'wb')
writer.write(outputFile)
outputFile.close()
mylistboxProgress.insert(tk.END, "File saved as: "+outputName.name)
else:
mylistboxProgress.insert(tk.END, "File not saved")
for i in range(0, len(pdfFile)):
pdfFile[i].close()
return
示例13: save_file
def save_file():
file = filedialog.asksaveasfile(mode="w")
if file != None:
# chop the last character from get, as an added extra return
data = self.textPad.get("1.0", END + "-1c")
file.write(data)
file.close()
示例14: saveFile
def saveFile(content) :
'''
Use a Tkinter file dialog to allow the user to save content to a file.
This is used for the results window in the UI.
'''
file = filedialog.asksaveasfile(mode = 'w', defaultextension = '.txt', initialfile = "results")
if file != None : print(content, file = file)
示例15: __askSaveFilePath
def __askSaveFilePath(self, extension):
file_path = filedialog.asksaveasfile(mode="w", defaultextension=extension)
#check if user cancelled saveFileDialog
if file_path is None:
return
#self.image_editor.image.write(file_path, format=extension)
self.image_editor.image.save(str(file_path.name))