Importing excel sheet using tkinter and openpyxl
The problem is that you are passing a button where the file_name should be, try like this:
Import all modules first
from tkinter import *from tkinter.filedialog import askopenfilefrom openpyxl import load_workbook
Create your window :
root = Tk()root.geometry('200x100')
Then create your function :
def open_file(): file = askopenfile(mode ='r', filetypes =[('Excel Files', '*.xlsx *.xlsm *.sxc *.ods *.csv *.tsv')]) # To open the file that you want. #' mode='r' ' is to tell the filedialog to read the file # 'filetypes=[()]' is to filter the files shown as only Excel files wb = load_workbook(filename = file.name) # Load into openpyxl wb2 = wb.active #Whatever you want to do with the WorkSheet
then everything else :
btn = Button(root, text ='Open', command = open_file)btn.pack(side='top')mainloop()