1

When I try to get value of variable I get an error:

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

Here is code:

class whatever(x):

    def get_inpt(self):
        print (self.createWidgets().name.get())

    def createWidgets(self):
        name = Entry(self).grid()

I want to have createWidgets function because of tidiness and also keep get_inpt out of it.

Q: How to process name value between functions?

Working on Python-3.4.2

Fred
  • 103
  • 3
  • 14

1 Answers1

1

Right now, your createWidgets method isn't returning anything, so the result of self.createWidgets() is None. None objects don't have a name attribute, so you're getting an error.

Assign the Entry to an attribute of self, such as self.name. Also, you should never assign and grid on the same line - then the variable won't contain the widget, it will contain the return value of grid, which is None.

class whatever(x):
    def __init__(self):
        self.createWidgets()
    def get_inpt(self):
        print (self.name.get())
    def createWidgets(self):
        self.name = Entry(self)
        self.name.grid()
Kevin
  • 74,910
  • 12
  • 133
  • 166