1

Using python I wrote the code below. I am trying to make a small calculator which multiplies an input by 5. When using the .get() command, I get 'NoneType' object has no attribute 'get'. Can anyone help?

from Tkinter import *

def calc_handler():
    question = entry.get()
    answer = question * 5
    print answer

main = Tk()
main.title('Calculator')
main.geometry('350x100+300+100')

instructions = Label(main, text='Input A Number And I Will Multiply It By 5').grid(row=0, columnspan=2)
entry = Entry(main).grid(row=1, columnspan=2)
enter = Button(main, text='Click Here To Calculate', command=calc_handler).grid(row=3, column=1)
clear = Button(main, text='Clear').grid(row=3, column=2)



mainloop()

1 Answers1

1

It is hard to define why it happens (I reckon grid return a None object) but change this line:

entry = Entry(main).grid(row=1, columnspan=2)

To:

entry = Entry(main)
entry.grid(row=1, columnspan=2)

And the reason why it never actually multiplies is that because question is a string thus you need to convert it to a integer by using the int() function before multiplying it:

def calc_handler():
    question = entry.get()
    answer = int(question) * 5
    print answer
K DawG
  • 13,287
  • 9
  • 35
  • 66