1

I'm making a simple print programme with a Tkinter GUI. I get the error

"'NoneType' object has no attribute 'get' "

everytime I click the print button and I'm not sure why. Any help is appreciated, thanks.

from tkinter import*

root=Tk()
root.title("Communication Aid")
root.resizable(0,0)

def printing():
    printed = Input.get()
    print(printed)

mainframe = Frame(root)
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

button = Button(mainframe, text = "Print", command= printing).grid(column=1, row=2, sticky=W)

Input = Entry(mainframe).grid(column=1, row=1, sticky=W)


root.mainloop()
nbro
  • 15,395
  • 32
  • 113
  • 196
Conor
  • 31
  • 1

1 Answers1

0
button = Button(mainframe, text = "Print", command= printing).grid(column=1, row=2, sticky=W)

Input = Entry(mainframe).grid(column=1, row=1, sticky=W)

If you assign a variable and grid on the same line, the variable will hold the return value of grid, which is None. Assign and grid on separate lines.

button = Button(mainframe, text = "Print", command= printing)
button.grid(column=1, row=2, sticky=W)

Input = Entry(mainframe)
Input.grid(column=1, row=1, sticky=W)
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • Thank you very much! I didn't release this had been answered before and I'm under pressure to complete my project for a national secondary school science fair competition and this was an annoying problem. Thanks. – Conor Dec 23 '14 at 16:08