Cut copy and paste Data in Entry widget



Cut copy and paste using entry widget


We will copy ( or cut ) data from one entry box and paste the same in another entry widget.


Tkinter select all data from entry box and copy or cut to clipboard to paste in another entry box



Button b1: Select All Used for selecting all the data in entry box e1.
Button b2: CutCut the selected data of e1 and store in clipboard.
Button b3: CopyCopy the selected data of e1 and store in clipboard.
Button b4: PastePaste the clipboard data inside entry e2.

Selecting text inside Entry box

On click of the button b1, the command will execute this code to select all the text.
e1.select_range(0,'end')

Cut or Copy the selected text

Data will be shifted to clipboard.
e1.event_generate("<<Cut>>"),
e1.event_generate("<<Copy>>")

Pasting data from Clipboard to entry widget

Here e2 is another entry widget where data will be pasted from the clipboard.
e2.event_generate("<<Paste>>")
Full code is here
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("400x250")  
my_w.title("plus2net.com")  # Adding a title
l1=tk.Label(my_w,text='Name',font=20)
l1.grid(row=0,column=0,padx=2,pady=20)

e1=tk.Entry(my_w,font=20,width=28,bg='yellow') # top entry widget for inputs
e1.grid(row=0,column=1,columnspan=4)

b1=tk.Button(my_w,text='Select All',
	command=lambda:e1.select_range(0,'end'),font=20,bg='lightgreen')
b1.grid(row=1,column=1,padx=2)

b2=tk.Button(my_w,text='Cut',
	command=lambda:e1.event_generate("<<Cut>>"),font=20,bg='lightyellow')
b2.grid(row=1,column=2)
b3=tk.Button(my_w,text='Copy',
	command=lambda:e1.event_generate("<<Copy>>"),font=20,bg='lightblue')
b3.grid(row=1,column=3)
b4=tk.Button(my_w,text='Paste',
	command=lambda:e2.event_generate("<<Paste>>"),font=20,bg='cyan')
b4.grid(row=1,column=4)

e2=tk.Entry(my_w,font=20,width=28,bg='yellow') # button entry for paste
e2.grid(row=2,column=1,columnspan=4,pady=20)
my_w.mainloop()
Entry Cut copy paste in Text widgets Python Tkinter Projects Spinbox DoubleVar
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer