Python Forum
AttributeError: 'NoneType' object has no attribute 'get'
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'NoneType' object has no attribute 'get'
#1
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?
Reply
#2
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)
Recommended Tutorials:
Reply
#3
Awesome it worked! thanks! :D
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'NoneType' re.search philnyland 1 250 Jan-20-2024, 03:24 AM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 679 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 719 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  TypeError: 'NoneType' object is not callable akbarza 4 920 Aug-24-2023, 05:14 PM
Last Post: snippsat
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,531 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 704 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,665 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 686 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,214 Apr-15-2023, 05:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020