Tkinter askdirectory()没有显示在屏幕上



我试图让用户选择他们想要保存文件的目录,但是任何时候我在初始askopenfilename()之后调用Tkinkter函数,它只是挂起。askopenfilename()在第一次调用时工作,但askdirectory()之后就不能工作了。这只是我在摆弄Tkinter,因为我是新手。熊猫的东西都工作得很好,没有错误显示;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']])

由于某种原因,程序在退出根目录时挂起。从代码中删除以下内容:

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']])

最新更新