-2
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

Shorn
  • 718
  • 2
  • 13

1 Answers1

1

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()
Michael M.
  • 10,486
  • 9
  • 18
  • 34
Shorn
  • 718
  • 2
  • 13
  • thanks. im new to tkinter and just getting around. how come putting the pack() on a different line make it return a veriable. sorry for me asking – Declan Davis Feb 16 '23 at 03:39
  • As previously mentioned, pack() does not return a variable. If you have it on the same line, you are assigning the return from pack() to ent_Filepath. – Shorn Feb 16 '23 at 03:41