How to copy typed text from an Entry textbox?

33 views Asked by At

I'm having a slight problem while using python, I want to make a program which can copy a text you've written once you press a button. However, I have been unable to find a way to do it. With pyperclip I have been able to get close but it's not good enough. Summarized: I want to write text in a textbox and with a button I want to copy it to clipboard.

The code I've written:

import pyperclip as pc
import tkinter as tk
from tkinter import Canvas
from tkinter import Button

def Tekstbox():

 root = tk.Tk()
#window
 canvas1 = Canvas(root,
                  width = 400,
                  height = 300)

 canvas1.pack()
#textbox
 entry1 = tk.Entry(root)

 canvas1.create_window(200, 140,
                   window = entry1)

#copybutton
 button1 = Button(root,
                   text = 'copy',
                   command = pc.copy(entry1 + 'EFGH'))  #Random letters just for test purposes
                                    #Entry1 would be the input in the textbox that I want to copy and
                                                            #then combine it with 'EFGH' on clipboard.
 button1.pack()

 root.mainloop()


Tekstbox()
0

There are 0 answers