the entry .get() function is not recognized

Question:

if __name__ == "__main__":
    import tkinter as tk
    from tkinter import ttk
    window = tk.Tk()
    def clear():
        for btn in toClear.copy():
            btn.destroy()
            toClear.remove(btn)
    def readFilefunction():
        clear()
        def enter():
            path = ent_Filepath.get()
            readFile(path)
        #window.geometry("250x75+250+75")
        ent_Filepath = tk.Entry(window, width=15).pack()
        btn_Enter = tk.Button(window,command=enter,text="Enter").pack()#place(x=30,y=20)
    def searchFilefunction():   
        txt_Model = ttk.Entry(window)
        txt_Size = ttk.Entry(window)
        print('searchFile')
    def addRecordfunction():
        print('addRecord')
    def modQuantityfunction():
        print('modQuantity')
    functions = {
        "readFile": readFilefunction,
        "searchFile": searchFilefunction,
        "addRecord": addRecordfunction,
        "modQuantity": modQuantityfunction
    }
    toClear = []
    title = tk.Label(text= "Please choose a function")
    title.pack()
    toClear.append(title)
    for text, fu1 in functions.items():
        frame = tk.Frame(master=window)
        frame.pack(side=tk.LEFT)
        button = tk.Button(
            master=frame,
            text=text,
            width=10,
            height=2,
            command=fu1
        )
        button.pack()
        toClear.append(button)
    window.mainloop()

enter image description here

the .get function gets the error

Cannot access member "get" for type "None" Pylance(reportGeneralTypeIssues)[Ln 42, Col 33]
Member "get" is unknown

and i’m not sure why

it was working but i changed something but cant remember what sorry. im not sure how to fix it from here. please dont hesitate to ask for any further details

Asked By: Declan Davis

||

Answers:

The issue is caused because ent_Filepath is None. If you look at line 15 of the included code, you will see ent_Filepath = tk.Entry(window, width=15).pack(). pack() does not return a value, so you get None. What you should be doing instead is

ent_Filepath = tk.Entry(window, width=15)
ent_Filepath.pack()
Answered By: Shorn
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.