Python Forum
[Tkinter] text edition in Text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] text edition in Text
#2
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.
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]))
crook79 likes this post
Reply


Messages In This Thread
text edition in Text - by crook79 - Aug-08-2021, 07:26 PM
RE: text edition in Text - by deanhystad - Aug-08-2021, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Button to +1 in text box everytime it's clicked martyloo 2 182 May-02-2024, 10:30 AM
Last Post: lillydalson
  Transparent window background, but not text on it muzicman0 7 2,970 Feb-02-2024, 01:28 AM
Last Post: Joically
  [Kivy] Create a function to store text fields and drop downs selection in KivyMD floxia 0 1,699 Dec-18-2022, 04:34 AM
Last Post: floxia
  [Tkinter] Updating tkinter text BliepMonster 5 6,194 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  Can't change the colour of Tk button text Pilover 6 14,916 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] QLineEdit Caret (Text Cursor) Transparency malonn 5 2,885 Nov-04-2022, 09:04 PM
Last Post: malonn
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,569 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [PyQt] Determine whether text in QTableView cell is fully visible or not random_nick 0 1,016 Oct-27-2022, 09:29 PM
Last Post: random_nick
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,969 Aug-23-2022, 09:11 PM
Last Post: Extra
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,055 Jun-26-2022, 06:26 PM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020