0

I am having an issue getting this code to parse in tkinter. Two issues happen. I can't get the everb5 variable to pass into the generate function.

class App(Tk): 
def __init__(self): 
    Tk.__init__(self)
    self.everb5 = Entry(self).grid(row = 19, column = 2)
    self.btn = Button(self, text = "Generate", command = self.generate).grid(row = 25, column = 3, columnspan = 3)
def generate(self):
    self.everb5.config(text= "Hello")

Must I also pass the variable to the generate function like so...

def generate(self,everb5)

I also have about 23 variables that have to work in the generate function from the init function. Next steps? Variable containing an array of all variables? I am making a mad libs game and need to pass the answers from Tk() Entry() function to generate() and then i planned on using the .format function to replace the "blank spaces" used in mad libs with the answers provided from the user. I have the button working now, I just need to know how to pass the variables between functions.

2
  • Print self everb5. It is None. You have to first catch the return from Entry() and then grid() it on a separate line so the None is returned on a separate line. Next time please include the error message as a None type object, etc. message makes it obvious what is wrong. Commented Dec 9, 2014 at 1:37
  • Also you use insert or a textvariable for the Entry widget effbot.org/tkinterbook/entry.htm Commented Dec 9, 2014 at 1:41

1 Answer 1

1

I guess the problem is that self.everb5 and self.btn are none. The reason is that grid returns none. You should execute grid after you make an instance of Entry or Button:

class App(Tk): 
    def __init__(self): 
        Tk.__init__(self)
        self.everb5 = Entry(self)
        self.everb5.grid(row = 19, column = 2) #<-- here
        self.btn = Button(self, text = "Generate", command = self.generate)
        self.btn.grid(row = 25, column = 3, columnspan = 3) #<-- here

    def generate(self):
        self.everb5.config(text= "Hello")
Sign up to request clarification or add additional context in comments.

1 Comment

Apparently it didn't like me trying to use one liners. Thank you, I will make the appropriate changes. Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.