[Tutor] Copy/Paste in Tkinter
Pooja Bhalode
poojabhalode11 at gmail.com
Fri Feb 3 19:24:49 EST 2017
Hi,
I am trying to write a simple Tkinter code in Python in order to
demonstrate select/copy/paste/cut functionalities using keyboard keys and
menu options.
I tried looking up online, but I am finding examples of these in which they
create an event and then it is used:
eg.:
import Tkinter
def make_menu(w):
global the_menu
the_menu = Tkinter.Menu(w, tearoff=0)
# the_menu.add_command(label="Select")
the_menu.add_command(label="Cut")
the_menu.add_command(label="Copy")
the_menu.add_command(label="Paste")
def show_menu(e):
w = e.widget
# the_menu.entryconfigure("Select",command=lambda:
w.event_generate("<<Select>>"))
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)
root = Tkinter.Tk()
make_menu(root)
e1 = Tkinter.Entry(); e1.pack()
e2 = Tkinter.Entry(); e2.pack()
e1.bind_class("Entry", "<Double-1><ButtonRelease-1>", show_menu)
root.mainloop()
I was wondering if someone could please tell me a simplified different way
of doing this, that would be great. Thank you.
Pooja
More information about the Tutor
mailing list