0

I am trying to make a tkinter program that calculates the land transfer tax. When I run this code, it gives me the following error when I try to calculate it:

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'

Here is the code that I have:

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

Can someone tell me what is wrong with my program?

2
  • Just a shot in the dark: have you verified that entry_box is being set / created successfully? Commented Mar 23, 2019 at 3:51
  • Yes I have. It shows up and looks exactly like the tutorials say it should.
    – Jerry Cui
    Commented Mar 23, 2019 at 18:43

0

You must log in to answer this question.

Browse other questions tagged .