0
from tkinter import *
window = Tk()
window.title("calculator")
e = Entry(window, width=35, borderwidth=5).grid(row=0, column=0, columnspan=3, padx=10, pady=10)

def button_click(number): 
    e.delete(0, END)
    e.insert(0, number)
       
# define buttons    
button_1 = Button(window, text="1", padx=40, pady=20, command=lambda: button_click(1))
button_2 = Button(window, text="2", padx=40, pady=20, command=lambda: button_click(2))
button_3 = Button(window, text="3", padx=40, pady=20, command=lambda: button_click(3))

button_4 = Button(window, text="4", padx=40, pady=20, command=lambda: button_click(4))
button_5 = Button(window, text="5", padx=40, pady=20, command=lambda: button_click(5))
button_6 = Button(window, text="6", padx=40, pady=20, command=lambda: button_click(6))

button_7 = Button(window, text="7", padx=40, pady=20, command=lambda: button_click(7))
button_8 = Button(window, text="8", padx=40, pady=20, command=lambda: button_click(8))
button_9 = Button(window, text="9", padx=40, pady=20, command=lambda: button_click(9))

button_0 = Button(window, text="0", padx=40, pady=20, command=lambda: button_click(0))
button_add = Button(window, text="+", padx=39, pady=20, command=lambda: button_click())
button_equal = Button(window, text="=", padx=91, pady=20, command=lambda: button_click())
button_clear = Button(window, text="clear", padx=79, pady=20, command=lambda: button_click())
# put the buttons on the screen

window.mainloop()

The error:

 File "C:\script\kinter calculator.py", line 21, in <lambda>
    button_7 = Button(window, text="7", padx=40, pady=20, command=lambda: button_click(7))
  File "C:\script\kinter calculator.py", line 7, in button_click
    e.delete(0, END)
AttributeError: 'NoneType' object has no attribute 'delete'
>>> 
halfer
  • 19,824
  • 17
  • 99
  • 186
sam
  • 9
  • 1
  • 1
    You can improve your question by adding code formatting, including a tag for the language you're using, and choosing a title that reflects the actual problem you are facing. – beaker Jan 31 '22 at 17:14
  • Does this answer your question? [Tkinter: AttributeError: NoneType object has no attribute ](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) – Bryan Oakley Jan 31 '22 at 20:32
  • You are missing grid for every buttons. button_1.grid(row=1, column=0, columnspan=3, padx=10, pady=10). Change this to every buttons command=lambda: button_click). You don't need parenthesis bracket. – toyota Supra May 30 '22 at 18:06

0 Answers0