我從我的 .py 專案創建了一個 .exe 檔案。當我嘗試在桌面上保存和輸出 .csv 檔案時,我得到“錯誤 13 權限被拒絕”,因為我沒有管理員權限。相反,我需要將檔案保存到 C:/Users/Public 以使其作業。那么,每次我收到“錯誤 13”時,如何使用 Tkinter 制作帶有此訊息的彈出視窗?錯誤僅在 cmd 中顯示。
## Write output to csv file
def save_file():
path_to_output_file = fd.asksaveasfilename()
if not path_to_output_file:
return
file_count = 1
for rows in range(len(df)):
if rows % 500 == 0:
df[rows:rows 500].to_csv(path_to_output_file str(file_count) '.csv', index=False, header=True, quoting=csv.QUOTE_NONNUMERIC)
file_count = 1
uj5u.com熱心網友回復:
如果您已經收到錯誤訊息,您可以使用tkinter.messagebox.showinfo函式創建一個彈出視窗并顯示錯誤訊息。您可以在此處找到檔案:
https ://docs.python.org/3/library/tkinter.messagebox.html
uj5u.com熱心網友回復:
謝謝!有效!
try:
df[rows:rows 500].to_csv(path_to_output_file str(file_count) '.csv', index=False, header=True, quoting=csv.QUOTE_NONNUMERIC)
except PermissionError:
messagebox.showinfo('Can\'t save a file', f'File can\'t be saved to {path_to_output_file} as you don\'t have admin privileges.\nYou need to save a file to \'C:/Users/Public\'')
在此處輸入影像描述
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/411592.html
標籤:
