【问题标题】:Getting an AttributeError constantly in fetching from an Entry Widget. How to fix this? [duplicate]在从 Entry Widget 获取时不断获取 AttributeError。如何解决这个问题? [复制]
【发布时间】:2020-09-13 04:30:41
【问题描述】:

这是代码

from tkinter import*

win = Tk()

win.title('My application')

e = Entry(win).pack()

def click():

    label = Label(win, text = 
            "Hello" + 
            e.get()).pack()

button = Button(win, text = 
        'Enter your name', 
        command = 
        'click').pack()

win.mainloop()

当我输入名称并单击我创建的按钮时,我最终会遇到类似的错误, " 属性错误:'NoneType' 对象没有属性 'get' ".

谁能告诉我为什么我不断收到这个属性错误,我该如何解决这个问题?顺便说一句,我是一个正在尝试学习基础知识的初学者。

【问题讨论】:

    标签: tkinter widget fetch tkinter-entry getattribute


    【解决方案1】:

    e = Entry(win).pack() 更改为

    e = Entry(win)
    e.pack()
    

    这是因为 e = Entry(win).pack() 返回 None 并因此返回错误。

    希望这对您有所帮助。

    干杯

    【讨论】:

    • 哇!非常感谢 !最后我得到了那个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2021-09-14
    • 2021-07-09
    • 2023-01-30
    • 2014-08-12
    相关资源
    最近更新 更多