Python Forum

Full Version: AttributeError: 'NoneType' object has no attribute 'get'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here's the program:

# !/usr/bin/python 3.5.2
# -*- coding: UTF-8 -*-

from tkinter import *
import math


class frame(Frame):

    def __init__(self, master = None):
        Frame.__init__(self, master)
 
        self.master = master

        self.init_frame()


    def init_frame(self):

        self.master.title("KunsFormule")

        self.pack(fill=BOTH, expand=1)

        self.ratio1 = Entry(self, width=30).pack(side=TOP, padx=10, pady=10)

        self.doenSom = Button(self, text="Doen Som",
                              command=self.data_prossesering)

        self.doenSom.place(x=155, y=40)

        self.uiset = Entry(self, width=20).pack(side=TOP, padx=50, pady=50)

        
    def data_prossesering(self):
        
        e = self.ratio1.get()
        e.split() 
     
 
        r1 = float(e[0]) * float(e[1])
        r2 = float(e[2]) * float(e[3])

        a = r1/r2
    
        return TkmessageBox.showInfo(math.sqrt(a)
root = Tk()
root.geometry("400x300")

app = frame(root)

root.mainloop()
the objective of this program is to solve the following mathematical problem: the square root of the answer of 4 cross-multiplied numbers which are separated in pairs and divided by each other. the numbers are entered by the user in a text field, then when the button is clicked the square root appears in another text field below it. however, when i click the button, the following error appears:

Error:
Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__ return self.func(*args) File "/complete/path/to/file.py", line 42, in data_prossesering e = self.ratio1.get() AttributeError: 'NoneType' object has no attribute 'get'
Does anyone know how to fix this?
The grid, pack, and place methods of every Tkinter widget operate in-place and always return None. This means that you cannot call them on the same line as you create a widget. Instead, they should be called on the line below:
self.ratio1 = Entry(self, width=30)
self.ratio1.pack(side=TOP, padx=10, pady=10)
Awesome it worked! thanks! :D