当用户保存文件时,我想默认在文件对话框中放置一个值。任何人都可以建议它的语法?
saveFilePath = fileDialog.asksaveasfile(mode='w', title="Save the file", defaultextension=".txt")
Run Code Online (Sandbox Code Playgroud)
例如:打开文件对话框时应填写NewFile
简短的答案是在 saveFilePath 中使用: intialfile = 'default_file_name'。下面是一个 Python 3 块,您可以使用 tkinter 从 CSV 读取数据帧并“另存为”。
def ExportApplications():
#reads the file to dataframe
df_testFile = pd.read_csv('test.csv')
#creates SaveAs dialogue and prompts user to save
#you can enter multiple file type formats in data FYI
data = [('csv', '*.csv')]
file_out = asksaveasfile(filetypes=data, defaultextension=data,initialfile = "This_is_the_default_file_name_when_saving")
#writes output to location specified by user in "Save As" dialogue
df_testFile.to_csv(file_out, index=False, encoding="utf-8")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7071 次 |
| 最近记录: |