Aug-08-2021, 09:16 PM
Your problem is test_input is one string, not three strings. Your function will have to split test_input into three strings, prepend "a:" to each string, and put the strings back together.
You can use str.split() for this if you know the delimiter and the delimiter is only used to separate words in the string. This is an example where words are separated by a space.
You can use str.split() for this if you know the delimiter and the delimiter is only used to separate words in the string. This is an example where words are separated by a space.
words = ('one two three').split(' ') # Split string into words separated by a space row_words = [f'a:{word}' for word in words] # Prepend a: to each word print(' '.join(row_words)) # Join the words together separated by a space
Output:a:one a:two a:three
I think you will want to use newline ('\n') as the separator, and you might need to strip any trailing newline before splitting into words.def click(): text = text1.get("1.0", END).strip().split('\n') text2.insert(1.0, '\n'.join([f'a:{word}' for word in text]))