[Tkinter-discuss] copy-enabled Label

Michael Lange klappnase at web.de
Sun May 24 13:57:39 CEST 2009


Hi,

On Sun, 24 May 2009 10:30:03 +0200
"Michael O'Donnell" <michael.odonnell at uam.es> wrote:

> Hi O.C.
> 
> The following code shows how to use an Entry widget
> which ignores all key presses except Control-c and Control-x
> (copy and cut at least under windows).
> 
> from Tkinter import *
> 
> def copy1(event):
>     pass
> 
> def printKey(event):
>     return "break"
> 
> main=Tk()
> 
> wt=Entry(main, bg="white")
> wt.insert(END, "FRed")
> wt.pack(side=LEFT, fill=BOTH,expand=True)
> wt.bind("<Control-c>", copy1)
> wt.bind("<Control-x>", copy1)
> wt.bind("<KeyPress>", printKey)
> main.mainloop()
> 
> 

The copy-enabled label should be much easier to implement:

>>> from Tkinter import *
>>> root = Tk()
>>> e=Entry(root,relief='flat',bd=0,takefocus=0,highlightthickness=0)
>>> e.pack()
>>> e.insert('end', 'foobar')
>>> e.config(state='readonly')

Regards

Michael


More information about the Tkinter-discuss mailing list