1

I have a bit of a problem. I have a text widget for user input instead of an entry widget and cannot seem to fetch the data from it. For example with an entry widget, you use .get() but what would you use for a text widget?

Thanks for your help...

Label(insertscreen, text="Please enter the Recipe ID").grid(row=0, sticky=W)
Label(insertscreen, text="Please enter the Recipe Name").grid(row=1, sticky=W)
Label(insertscreen, text="Please enter the Method of the Recipe").grid(row=2, sticky=W)
Label(insertscreen, text="Please enter the First Ingredient").grid(row=3, sticky=W)
Label(insertscreen, text="Please enter the Second Ingredient").grid(row=4, sticky=W)
Label(insertscreen, text="Please enter the Third Ingredient").grid(row=5, sticky=W)
Label(insertscreen, text="Please enter the Fourth Ingredient").grid(row=6, sticky=W)
Label(insertscreen, text="Please enter the Fifth Ingredient").grid(row=7, sticky=W)
Label(insertscreen, text="Please enter the Cooking Time, in minutes").grid(row=8, sticky=W)

Enter1= Entry(insertscreen)
Enter1.grid(row=0, column=1)
Enter2= Entry(insertscreen)
Enter2.grid(row=1, column=1)
Enter3= Text(insertscreen, width = 50, height = 10)
Enter3.grid(row=2, column=1)
Enter4= Entry(insertscreen)
Enter4.grid(row=3, column=1)
Enter5= Entry(insertscreen)
Enter5.grid(row=4, column=1)
Enter6= Entry(insertscreen)
Enter6.grid(row=5, column=1)
Enter7= Entry(insertscreen)
Enter7.grid(row=6, column=1)
Enter8= Entry(insertscreen)
Enter8.grid(row=7, column=1)
Enter9= Entry(insertscreen)
Enter9.grid(row=8, column=1)

#Entering the new recipe into the database
def submit_recipe():

global Enter1, Enter2, Enter3, Enter4, Enter5, Enter6, Enter7, Enter8, Enter9, new_db

ID = Enter1.get()
Name = Enter2.get()
Method = Enter3.get()
Ing1 = Enter4.get()
Ing2 = Enter5.get()
Ing3 = Enter6.get()
Ing4 = Enter7.get()
Ing5 = Enter8.get()
TimeofRec = Enter9.get()
2
  • contents = text.get(1.0, END) effbot.org/tkinterbook/text.htm Commented Apr 1, 2014 at 11:28
  • THANKS SO MUCH ATLASOLOGIST... IT WORKS!!!!!!!!!!!!!! Commented Apr 1, 2014 at 11:39

2 Answers 2

2

The text widget uses get but as the widget manages multiple lines of text it has selectors to specify regions of the content. See the tkdocs site for a tutorial on the use of this widget and the manual page for the full details. An example to get the first line of text:

firstline = textWidget.get("1.0", "1.0 lineend")
Sign up to request clarification or add additional context in comments.

Comments

0

The two most common ways to retrieve text from a Text widget are as follows:

1) grab all the text in the widget:

    all_text = TextWidget.get('1.0', Tkinter.END)

2) grab the text that is currently selected:

    ranges = TextWidget.tag_ranges(Tkinter.SEL)
    if ranges:
        selected_text = TextWidget.get(*ranges)

Comments

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.