`.get()`函数未被识别。

huangapple go评论62阅读模式
英文:

the entry .get() function is not recognized

问题

代码中的问题在于 ent_Filepath = tk.Entry(window, width=15).pack() 这一行代码中,.pack() 方法返回的是 None,因此在后续的 enter 函数中无法使用 .get() 方法。

要解决这个问题,您可以将 .pack() 拆分成两行,并将 .pack() 方法应用于单独的行,如下所示:

ent_Filepath = tk.Entry(window, width=15)
ent_Filepath.pack()

这样,您就可以在 enter 函数中使用 ent_Filepath.get() 而不会出现 "Cannot access member 'get' for type 'None'" 的错误。

此外,您的代码中还有其他地方使用了 HTML 实体编码(如 "')。如果您要在代码中使用引号或撇号,请使用原始字符而不是 HTML 实体编码,例如 "__main__" 而不是 "__main__"'searchFile' 而不是 'searchFile'。这将有助于确保代码的正确性。

以上是代码的翻译和修复建议,如果您有任何其他问题或需要进一步的帮助,请随时提出。

英文:
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()

`.get()`函数未被识别。

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

答案1

得分: 1

问题是因为ent_Filepath的值为None。如果你看一下附带代码的第15行,你会发现ent_Filepath = tk.Entry(window, width=15).pack()pack()没有返回值,所以你得到了None。你应该改成这样做:

ent_Filepath = tk.Entry(window, width=15)
ent_Filepath.pack()
英文:

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()

huangapple
  • 本文由 发表于 2023年2月16日 11:28:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75467569.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定