The Code:
import pandas as pd
from tkinter import *
from tkinter import filedialog as fd
app = Tk()
file_path = ''
def set_file_path(path):
global file_path
file_path = path
def open_text_file():
filetypes = (
('Excel files', '*.xlsx'),
('All files', '*.*')
)
file = fd.askopenfile(filetypes=filetypes)
set_file_path(file)
def main(row, column, file):
file = pd.read_excel(file)
row_new = row - 1
column_new = column - 1
text = file[column_new][row_new]
return text
app.title('XLSX Reader')
app.geometry("400x400")
open_button = Button(app, text='Choose File', command=open_text_file)
open_button.pack()
row = Entry(app)
row.pack()
column = Entry(app)
column.pack()
Submit = Button(app, text='Get Text', command=main(row=row,column=column,file=file_path))
Submit.pack()
output = main()
label = Label(text=output)
label.pack()
app.mainloop()
Error:
Traceback (most recent call last):
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\main.py", line 37, in <module>
Submit = Button(app, text='Get Text', command=main(row=row,column=column,file=file_path))
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\main.py", line 22, in main
file = pd.read_excel(file)
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\kernal\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\kernal\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\kernal\lib\site-packages\pandas\io\excel\_base.py", line 482, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\kernal\lib\site-packages\pandas\io\excel\_base.py", line 1652, in __init__
ext = inspect_excel_format(
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\kernal\lib\site-packages\pandas\io\excel\_base.py", line 1525, in inspect_excel_format
with get_handle(
File "C:\Users\91989\Documents\Arnav_Mann\Study\Science\Computer\Python\GraficalUserInterface\Excel_files\kernal\lib\site-packages\pandas\io\common.py", line 865, in get_handle
handle = open(handle, ioargs.mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
Process finished with exit code 1
I am trying to make a python application in Tkinter that allows the user to get a specific cell. But whenever I tried to run the code, I got the error that there is no file or directory: ''. I was expecting the code to provide a GUI that will allow the user to give the specific cell. Can anyone help.