为什么我的 Tkinter 输入框被归类为“NoneType”?

为什么我的 Tkinter 输入框被归类为“NoneType”?

我正在尝试编写一个计算土地转让税的 tkinter 程序。当我运行此代码时,尝试计算时出现以下错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Angela\AppData\Local\Programs\Python\Python37-    32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:/Users/Angela/PycharmProjects/Editor/Editor.py", line 16, in <lambda>
    ok = Button(master, text="Calculate tax", command= lambda: callback(master, entry_box)).grid(row=0, column=2)
  File "C:/Users/Angela/PycharmProjects/Editor/Editor.py", line 19, in callback
    price = entry_box.get()
AttributeError: 'NoneType' object has no attribute 'get'

这是我的代码:

master = Tk()

label = Label(master, text="Price of house: ").grid(row=0)
entry_box = Entry(master).grid(row=0, column=1)

ok = Button(master, text="Calculate tax", command= lambda: callback(master, entry_box)).grid(row=0, column=2)

def callback(master, entry_box):
    price = entry_box.get()
    price = int(price)
    tax_price = 275
    if price > 55000:
        tax_price += (250000 - 55000) * 0.1
    else:
        tax_price += 55000 * 0.05
    if price > 250000:
        tax_price += (368333 - 250000) * 0.15
    if price > 368333:
        tax_price += (400000 - 368333) * 0.15
    if price > 400000:
        tax_price += (2000000 - 400000) * 0.2
    if price > 2000000:
        tax_price += (price - 2000000) * 0.25
    show_tax_price = Label(master, text=tax_price).grid(row=0, column=3)



mainloop()

有人能告诉我我的程序出了什么问题吗?

相关内容