我正在创建一个带有两个按钮的窗口 - 一个用于导入 excel 文件,另一个用于在选择 excel 工作表后关闭窗口。我可以选择 excel 文件,但是当我单击确定时,我收到一个错误,指出我的文件路径无效。
使用 python 2.7
import Tkinter, tkFileDialog
import pandas as pd
root= Tkinter.Tk()
canvas = Tkinter.Canvas(root, width = 300, height = 300, bg = 'PowderBlue')
canvas.pack()
def getExcel ():
global df
import_file_path = tkFileDialog.askopenfilenames(title = 'Select file(s)',filetypes = (('Excel','*.xlsx'),('Comma Delimited','*.csv'),('xls', '*.xls')))
df = pd.read_excel (import_file_path)
print (df)
okay = Tkinter.Button(text='Okay', command=root.destroy, bg='blue', fg='white', font=('Arial', 10, 'bold'))
canvas.create_window(150, 200, window=okay)
browse_excel = Tkinter.Button(text='Import Excel File(s)', command = getExcel, bg='gray23', fg='white', font=('helvetica', 12, 'bold'))
canvas.create_window(150, 150, window = browse_excel)
root.mainloop()
我明白的错误
raise ValueError(msg.format(_type=type(filepath_or_buffer)))
ValueError: Invalid file path or buffer object type: <type 'tuple'>