Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter copy paste

import tkinter as tk
from tkinter import *


root = tk.Tk()
root.geometry("520x280")
root.resizable(0, 0)
root.title("Test Editor")


def make_menu(w):
    global the_menu
    the_menu = tk.Menu(w, tearoff=0)
    the_menu.add_command(label="Cut")
    the_menu.add_command(label="Copy")
    the_menu.add_command(label="Paste")

def printInput():
    paste = testEntry.get()
    #   1.0, "end-1c"   put this in the get method 
    lbl.config(text =paste)

def show_menu(e):
    w = e.widget
    the_menu.entryconfigure("Cut",
    command=lambda: w.event_generate("<<Cut>>"))

    the_menu.entryconfigure("Copy",
    command=lambda: w.event_generate("<<Copy>>"))

    the_menu.entryconfigure("Paste",
    command=lambda: w.event_generate("<<Paste>>"))

    the_menu.tk.call("tk_popup", the_menu, e.x_root, e.y_root)


printButton = tk.Button(root, text = "Print", command = printInput)

printButton.pack()


make_menu(root)

testEntry = tk.Entry(); testEntry.pack()
testEntry.bind_class("Entry", "<Button-3><ButtonRelease-3>", show_menu)


lbl = tk.Label(root, text = "")
lbl.pack()

root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: split string into groups of 3 chars python 
Python :: split a string into an array of words in python 
Python :: django templates 
Python :: python 2.7 datetime to timestamp 
Python :: numpy.random.choice 
Python :: get file in file zip python 
Python :: python get env 
Python :: regex for digits python 
Python :: randint() 
Python :: multiple bars barchart matplotlib 
Python :: estimate time to run a chunk of code in python 
Python :: knn with sklearn 
Python :: Simple Splash screen in pyqt5 
Python :: python cv2 canny overlay on image 
Python :: python unittest discover 
Python :: numpy randn with a shape of another array 
Python :: activate internal logging nlog 
Python :: list in list python 
Python :: python slit 
Python :: how to import and use keyboard with pygame 
Python :: how to install python in ubuntu 
Python :: how to combine strings python 
Python :: pickle example 
Python :: Could not find a version that satisfies the requirement ckeditor 
Python :: python how to play mp3 file 
Python :: make virtual environment wrapper python 3 
Python :: migrations.rename_field django 
Python :: python test type 
Python :: jupyter change cell to text 
Python :: how to rename files python 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =