[Tutor] Cut, Copy, and Paste in Tkinter (original) (raw)
Michael Lange klappnase at freenet.de
Thu Jul 8 22:15:07 CEST 2004
- Previous message: [Tutor] Cut, Copy, and Paste in Tkinter
- Next message: [Tutor] How to enable pausing my stop_watch.py ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 07 Jul 2004 23:06:30 -0400 Marv Boyes <marvboyes at att.net> wrote:
Hello, all. I'm trying to get a Paste function to work in a little Tkinter notepad-type application I'm working on (I hate Linux's Knotes and want to replace it on my machine). I've been using Martin Ultima's PyWord for inspiration and guidance, and I've had success adapting the Cut and Copy routines he used, but for some reason I can't manage a Paste.
Does this code snippet what you want?
################ from Tkinter import *
class Test(Text): def init(self, master, **kw): Text.init(self, master, **kw) self.bind('', self.copy) self.bind('', self.cut) self.bind('', self.paste)
def copy(self, event=None):
self.clipboard_clear()
text = self.get("sel.first", "sel.last")
self.clipboard_append(text)
def cut(self, event):
self.copy()
self.delete("sel.first", "sel.last")
def paste(self, event):
text = self.selection_get(selection='CLIPBOARD')
self.insert('insert', text)def test(): r = Tk() t = Test(r) t.pack(fill='both', expand=1) r.mainloop()
if name == 'main': test() ######################
The selection is copied to the window manager's clipboard if you call copy() or cut(), the paste() method shows how you get it back; I think it's the same that happens when you use the mouse to copy & paste.
I hope this helps
Michael
- Previous message: [Tutor] Cut, Copy, and Paste in Tkinter
- Next message: [Tutor] How to enable pausing my stop_watch.py ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]