為什麼我的 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()

有人能告訴我我的程式出了什麼問題嗎?

相關內容