我試圖允許用戶選擇他們想要將檔案保存到的目錄,但是無論何時我在初始之后呼叫 Tkinkter 函式askopenfilename(),它都會掛起。askopenfilename()第一次被呼叫時可以作業,但是askdirectory()之后就不會作業了。這只是我在玩 Tkinter,因為我是新手。Pandas 的東西一切正常,沒有顯示錯誤;Tkinter 在到達第 21 行 ( saved = askdirectory())后掛起。
from tkinter import Tk
from tkinter.filedialog import askdirectory, askopenfile, askopenfilename
excelArray = ["excel", "xlsx", "xl", "x", "exsel", "ex", "e"]
consoleArray = ["console", "c", "concole", "con", "consle"]
root=Tk()
root.withdraw()
pathToExcel = askopenfilename()
print(f"\nOpening the excel document located at: {pathToExcel}")
userOutput = input("\nWhere would you like the output to be? Console or Excel?").lower()
if userOutput in excelArray:
print("Where would you like to save it?")
saved = askdirectory()
print("Saved")
else:
print("\n")
print(test[['1', '2', '3']])
uj5u.com熱心網友回復:
出于某種原因,當根被撤銷時程式掛起。從您的代碼中,洗掉以下內容:
from tkinter import Tk
root = Tk()
root.withdraw()
所以最終的代碼將是:
from tkinter.filedialog import askdirectory, askopenfile, askopenfilename
excelArray = ["excel", "xlsx", "xl", "x", "exsel", "ex", "e"]
consoleArray = ["console", "c", "concole", "con", "consle"]
pathToExcel = askopenfilename()
print(f"\nOpening the excel document located at: {pathToExcel}")
userOutput = input("\nWhere would you like the output to be? Console or Excel?").lower()
if userOutput in excelArray:
print("Where would you like to save it?")
saved = askdirectory()
print("Saved")
else:
print("\n")
print(test[['1', '2', '3']])
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/323782.html
