几分钟前,我的功能运行良好。没有修改代码,只是安装了PyAudio。我根据主题收到错误。无论是从命令行还是 IDE 运行它都没有关系,同样的错误。有任何想法吗?
def DataFinder():
#imports and initialize
import pandas as pd
import tkinter as tk
finder = tk.Tk()
finder.withdraw()
__dataFlag = False
#ask user to select a file
__path = tk.filedialog.askopenfilename()
#check the extension to handle reader
#for csv files
if __path.endswith('.csv')==True:
df = pd.read_csv(__path,header=0)
return df
__dataFlag = True
#and for excel files
elif __path.endswith('.xls')==True:
df = pd.read_excel(__path,header=0)
return df
__dataFlag = True
#if a file is not a supported type display message and quit
else:
__dataFlag = False
#check if there is a data to be returned
if __dataFlag==True:
return df
else:
print('The file format is not supported in this version.')
最佳答案
以下代码对我不起作用:
import tkinter as tk
import tkinter.filedialog
但以下确实有效:import tkinter
import tkinter.filedialog
还有这个:import tkinter.filedialog
import tkinter as tk
希望这可以帮助笔记
正如 Vaidøtas 所提到的一、不能导入
filedialog
来自 tkinter
.因为你没有导入原版tkinter
但别名版本 tk
.
关于python-3.x - Python 3.6 - 属性错误 : module 'tkinter' has no attribute 'filedialog' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45533932/