copy-enabled Label
Hello, my application displays the result of a calculation in a Label. I would like the user to be able to copy this result somewhere else. I don't know how to enable this. I read on a mailing list that I could use a state=DISABLED Entry widget, but this doesn't work (I can't select anything with the mouse when it is DISABLED). I also found some complicated tcl/tk code which I did not understand. How to do ? I think a copy-enabled Label is a must. Best regards, O.C. Créez votre adresse électronique prenom.nom@laposte.net 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.
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() On Sun, May 24, 2009 at 12:17 AM, oc-spam66 <oc-spam66@laposte.net> wrote:
Hello,
my application displays the result of a calculation in a Label. I would like the user to be able to copy this result somewhere else. I don't know how to enable this.
I read on a mailing list that I could use a state=DISABLED Entry widget, but this doesn't work (I can't select anything with the mouse when it is DISABLED). I also found some complicated tcl/tk code which I did not understand.
How to do ? I think a copy-enabled Label is a must.
Best regards,
O.C.
Créez votre adresse électronique prenom.nom@laposte.net 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss
Hi, On Sun, 24 May 2009 10:30:03 +0200 "Michael O'Donnell" <michael.odonnell@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
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@web.de> wrote:
Hi,
On Sun, 24 May 2009 10:30:03 +0200 "Michael O'Donnell" <michael.odonnell@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@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss
participants (3)
-
Michael Lange -
Michael O'Donnell -
oc-spam66