如何修复AttributeError:'NoneType'对象没有tkinter条目的属性'get'

时间:2019-06-07 08:57:36

标签: python tkinter tkinter-entry

我的tkinter条目返回了none

我的主要代码也遇到了同样的问题,所以我决定编写一个较小的代码进行测试,但我遇到了同样的问题:

from tkinter import *

root = Tk()

a = Entry(root).grid(row = 0, column = 0)

b = Button(root,text = 'CLICK', command= lambda: test()).grid(row = 2, column = 2)

def test():
    print(a.get())


root.mainloop()

1 个答案:

答案 0 :(得分:0)

它是entry.grid(...)返回None

我想你想要

    from tkinter import *

    root = Tk()

    a = Entry(root)
    a.grid(row = 0, column = 0)

    b = Button(root,text = 'CLICK', command= lambda: test()).grid(row = 2, column = 2)

    def test():
        print(a.get())


    root.mainloop()