0
votes

My tkinter gui is using text widget and the following code is how I .get the data entered.

def all_descriptions():
    data = customer_description.get("1.0", END)
    print(data)

If user enters:

Item 1
Item 2
Item 3

It returns the values exactly like that.

Item 1
Item 2
Item 3

In an attempt to have the values returned in LIST format, I've also altered the .get function to be the following:

def all_descriptions():
    data = [customer_description.get("1.0", END)]
    print(data)

When I do this, it returns the entries like this:

['Item 1\nItem 2\nItem 3\n\n']

I have a couple questions for this process even though I've read through countless google and stackoverflow threads.

  1. Is the data entered returned as string values? I found a post mentioning this but want to verify.
  2. How can I access this data to run my functions on? I've tried this several different ways but my most recent attempt is below.
original_description = (all_descriptions())

# Product for Item One
def item_product(original_description, product_dict):
    for key in product_dict :
        if key in original_description():
            return product_dict[key]
    return ("What product is this?")
print(item_product(original_description, product_dict))

The above will obviously not work since I want to run the def item_product() on each line in the entry widget. Can anyone point me in the correct direction?

1

1 Answers

0
votes

customer_description.get("1.0", END) returns a single string. If you want a list of lines rather than a string, split on the newline character with split

Also, you should use "end-1c" instead of "end" or END. The latter will get an extra newline that tkinter automatically adds.

return customer_description.get("1.0", "end-1c").split("\n")