-3

Hello I have this code :

import Tkinter as tk

root = tk.Tk()
margin = 0.23
entry = tk.entry(root).grid(row=1,column=1)

def profit_calculator():
    profit = margin*int(entry.get())
    print(profit)

button_calc = tk.Button(root, text="Calculate", command=profit_calculator).grid(row=2,column=1)

root.mainloop()

I tried to execute this code I put a value in the entry but when I clicked on the button I get this :

AttributeError : 'NoneType' object has no attribute 'get'

I have to use grid absolutely but I don't know why I get this error...

Can you help me ?

Thank you :)

  • 2
    The code above doesn't raise the error you're claiming it does. It raises `AttributeError: 'module' object has no attribute 'entry'`. Which can be fixed by uppercasing the initial character of entry: `Entry(...`. – Nae Mar 21 '18 at 11:39

1 Answers1

0

entry right now is the return of grid which is always None. Separate the display call from widget object initiation. Replace:

entry = tk.entry(root).grid(row=1,column=1)

with:

entry = tk.Entry(root) # no predefined class named entry
entry.grid(row=1,column=1)
Nae
  • 14,209
  • 7
  • 52
  • 79