0
from tkinter import *
my_window = Tk()
def converter():
    F = float(entry_input.get())
    T = (F-32)*5/9
    display_Temp["text"] = str(T) 
Label(my_window,text="Enter Temperature in Farenheit = ").grid(row=0,column=0)
display_Temp = Label(my_window).grid(row=1,column=1)
entry_input = Entry(my_window).grid(row=0,column=1)
button = Button(my_window,text="Convert to Deg Celcius",command = converter,bd=8,relief="raised").grid(row=1,column=0)
my_window.mainloop()

I have entered 20 F in the GUI window that is created to convert the Fahrenheit a value to Deg Celsius. But, it gives following error message while I press the converter button: AttributeError: 'NoneType' object has no attribute 'get'

Please, refer the image to understand the error

enter image description here I have included the corrections as per the below accepted answer and it worked as given below: enter image description here

Msquare
  • 353
  • 1
  • 7
  • 17

1 Answers1

0

geometry managers (grid, pack, place) return None; you should not assign on the same line as you grid your widgets.

import tkinter as tk     # <-- avoid star imports


def converter():
    F = float(entry_input.get())
    T = (F - 32) * 5 / 9
    display_Temp["text"] = str(T) 


my_window = tk.Tk()

tk.Label(my_window, text="Enter Temperature in Farenheit = ").grid(row=0, column=0)

display_Temp = tk.Label(my_window)
display_Temp.grid(row=1, column=1)

entry_input = tk.Entry(my_window)
entry_input.grid(row=0, column=1)

button = tk.Button(my_window, text="Convert to Deg Celcius", command=converter, bd=8, relief="raised")
button.grid(row=1, column=0)

my_window.mainloop()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • Excellent. It worked. Thanks for lesson: don't import all modules through * and geometry managers which I have appended at end of each line will return 'none'. – Msquare Aug 06 '18 at 09:42
  • I have added 'entry_input.focus()' before the 'my_window.mainloop()' to move the cursor automatically to the entry location in GUI. But, it did not happen? How to do it? I mean, I want the cursor to move automatically to the entry location once the GUI is created. – Msquare Aug 06 '18 at 10:12