Home>

Help me.
An error occurs at the following location (after the if statement) and the file cannot be read. By the way, the file I want to read is .DAt.
What is the cause?

f = open (file_text,'r')
TypeError: expected str, bytes or os.PathLike object, not Entry

import tkinter as tk #GUI library
import tkinter.messagebox as tkm
import pandas as pd #csv Library to handle
import datetime as dt
from tkinter import file dialog
now = dt.datetime.now () #time
time = now.strftime ('% Y% m% d-% H% M% S')
def OpenFileDlg (tbox):
   ftype = [('','*')]
   dir ='.'
   #File dialog display
   filename = filedialog.askopenfilename (filetypes = ftype, initialdir = dir)
   #Display file path in text box
   tbox.insert (0, filename)
def btn_click (): #button function
    cc = str (txt1.get ()) # Substitute text box characters for cc
    sc = str (txt2.get ())
    if not len ​​(cc) == 6:
        tkm.showerror ("Enter error", "Customer number is 6 digits")
        return
    elif not len ​​(sc) == 7:
        tkm.showerror ("Enter error", "Employee number is 7 digits")
        return
    elif file_text.get () =='':
        tkm.showerror ('error','specify data file')
        return
    else: else:
        tkm.showinfo ("Information", "Saving CSV")
    f = open (file_text,'r')
    df = f.read ()
root = tk.Tk () #Tk class generation
root.geometry ('500x400 + 600 + 300') #screen size + position
root.title ('input screen') # screen title

#Customer number
lbl1 = tk.Label (text ='customer number', font = (u'MS Gothic', 11,'bold'))
lbl1.place (x = 85, y = 145)
txt1 = tk.Entry (width = 30)
txt1.place (x = 160, y = 150)
btn = tk.Button (root, text ='CSV output', width = 20, font = ("Menlo", 11), command = btn_click)
btn.place (x = 155, y = 220)
#employee number
lbl2 = tk.Label (text ='employee number', font = (u'MS Gothic', 11,'bold'))
lbl2.place (x = 85, y = 175)
txt2 = tk.Entry (width = 30)
txt2.place (x = 160, y = 180)
btn1 = tk.Button (root, text = "end", width = 20, font = ("Menlo", 11), command = root.destroy)
btn1.place (x = 155, y = 250)
#Excel file dialog
label = tk.Label (root, text ='data file', font = (u'MS Gothic', 10,'bold'))
label.place (x = 100, y = 95)
file_text = tk.Entry (root, width = 40)
file_text.place (x = 100, y = 115)
fdlg_button = tk.Button (root, text ='file selection', command = lambda: OpenFileDlg (file_text))
fdlg_button.place (x = 360, y = 110)
root.mainloop () # screen display