[Tkinter-discuss] copy-enabled Label

Michael O'Donnell michael.odonnell at uam.es
Sun May 24 15:49:19 CEST 2009


Hi Michael,

  Ahhh, my tkinter manual does not contain the state='readonly'
property. Seems I need to update my manual (John Shipman's
from 2003).

The original poster should note that every time you want to change
the text displayed, you need to change the state to normal, change the
text, and then re-assert state='readonly'.

Mick



On Sun, May 24, 2009 at 1:57 PM, Michael Lange <klappnase at web.de> wrote:
> 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
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>


More information about the Tkinter-discuss mailing list