0

I am trying to store the values of a Tkinter text box widget as a string to use in the rest of my code. But every time I have an enter function I am getting errors regarding the defying of the command is not possible in the functionCall.

class text():
    master = Tk()
    def on_button():
        print()
        t = Label(master, text="Enter Text ")
        e1 = Text(master, width=50, height = 25)
        e1.grid(row=0, column =1, rowspan=3, columnspan=4, padx=4, pady=4)
        functionCall = Button(master, text='Enter', command=Return)
        functionCall.grid(row=4, column=4)
    var = StringVar()
    def Return(self):
        self.TempVar=self.Entry.get()
        print(self.TempVar)

I am trying to connect the string inserted with the rest of my code. The concept works with a one-line entry box, but the idea is to have a bigger text box.

4
  • what are the errors that you are getting? The error likely tells you exactly what the problem is. Commented Mar 27, 2016 at 18:15
  • You are creating a root window inside the text(0 function -- is this the only place you're creating a root window? There seems to be a lot of code missing, since you don't show how the on_button function is being called. Commented Mar 27, 2016 at 18:16
  • This is the function to make a pop up window for the user to insert text. The rest of the code correlates based off of what is typed in the window by putting every key to a color window to show in a window. But the idea is to have the code go through the while loop: while index < len(name): letter = name[index] num = ord(letter) stack.append(num) index += 1 @BryanOakley The error is object of type 'NoneType has no len() Commented Mar 27, 2016 at 19:49
  • You need to use a Toplevel, not another instance of Tk. That may not be your only problem, but it's definitely a problem. Commented Mar 27, 2016 at 20:11

1 Answer 1

1

You should try something like that. You would use .get option for Text widget.

from tkinter import*
master = Tk()
def on_button():
   print()

def Return():
   TempVar=e1.get("1.0",END)
   print(TempVar)

t = Label(master, text="Enter Text ")
t.grid(row=0, column =1, rowspan=3, columnspan=4, padx=4, pady=4)
e1 = Text(master, width=50, height = 25)
e1.grid(row=1, column =1, rowspan=3, columnspan=4, padx=4, pady=4)
functionCall = Button(master, text='Enter', command=Return)
functionCall.grid(row=4, column=4)
Sign up to request clarification or add additional context in comments.

3 Comments

In terms of a length value within the string, would that be able to be recognized?
You wrote "You should try something like that." -- like what? What does "that" refer to in that sentence?
Oh, oh. So, more like "you should try something like the following code..."?

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.