f Text TK: How to Copy from a Text Widget ?"
Python Tkinter section

Frame TK: How is it Useful ?

Card image
Post by Amina Delali, July 12th, 2022

Description

In this code we will create 2 Text widgets, and a button:
1. in the first one, we will insert by default 2 lines of text
2. the second one will be empty
3. when you click on the button, the function
copyText will be called.
4. the function removes all the text from the second Text widget, get the text of the first widget, then insert it in the second widget



The Code

""" Text widget TK"""
from tkinter import *

main_window Tk()
main_window.geometry("400x400+400+200")
main_window.title("Text TK Widget")
main_window.configure(bg="#8800ff")

text Text(main_windowheight=10)
text.pack()
text2 Text(main_window,height=10)
text2.pack(pady=5)

text.insert('1.0',"This is the first  line\n")
text.insert(END,"This is the second line")

def copyText():
        text2.delete("1.0",END)
        text2.insert(ENDtext.get("1.0",END))
        

butGetButton(main_window,text="Copy Text",command =copyTextfg="#8800ff")
butGet.pack(pady=5)

main_window.mainloop()

The Output

Null




Something to say?

If you want to add something about this post, please feel free to do it by commenting below 🙂.