Adding the Copy Property to a Simple Histogram

W

W. eWatson

The code below produces a text window 60hx20w with a scroll bar. The
contents are something of a histogram of values from 0 to 255. If one tries
to copy the contents, Windows doesn't allow it. What needs to be done to
allow a copy and paste?

def ShowHistogram(self):
if not self.current_image:
return

if self.histogram:
self.histogram.destroy()

t = Toplevel( self.master )
t.title("Histogram")
t.bind( '<Destroy>', self.DestroyHistogram )
text = Text( t, height=60, width=20 )
scroll = Scrollbar(t, command=text.yview)
text.configure(yscrollcommand=scroll.set)
text.pack(side=LEFT, fill='both', expand=1)
scroll.pack(side=RIGHT, fill=Y)
self.histogram = t

hist = self.current_image.histogram()
for i in range(len(hist)):
msg = "%5d %6d\n" % (i,hist)
text.insert( END, msg )
--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 
S

Simon Forman

The code below produces a text window 60hx20w with a scroll bar. The
contents are something of a histogram of values from 0 to 255. If one tries
to copy the contents, Windows doesn't allow it. What needs to be done to
allow a copy and paste?

     def ShowHistogram(self):
         if not self.current_image:
             return

         if self.histogram:
             self.histogram.destroy()

         t = Toplevel( self.master )
         t.title("Histogram")
         t.bind( '<Destroy>', self.DestroyHistogram )
         text = Text( t, height=60, width=20 )
         scroll = Scrollbar(t, command=text.yview)
         text.configure(yscrollcommand=scroll.set)
         text.pack(side=LEFT, fill='both', expand=1)
         scroll.pack(side=RIGHT, fill=Y)
         self.histogram = t

         hist = self.current_image.histogram()
         for i in range(len(hist)):
             msg = "%5d %6d\n" % (i,hist)
             text.insert( END, msg )
--
                                W. eWatson

              (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
               Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

                     Web Page: <www.speckledwithstars.net/>


Do you mean that the Text widget doesn't let you copy-and-paste copy
its contents using selection and <Control-c>? That shouldn't have
anything to do with the contents of the Text widget.
 
W

W. eWatson

Simon said:
The code below produces a text window 60hx20w with a scroll bar. The
contents are something of a histogram of values from 0 to 255. If one tries
to copy the contents, Windows doesn't allow it. What needs to be done to
allow a copy and paste?

def ShowHistogram(self):
if not self.current_image:
return

if self.histogram:
self.histogram.destroy()

t = Toplevel( self.master )
t.title("Histogram")
t.bind( '<Destroy>', self.DestroyHistogram )
text = Text( t, height=60, width=20 )
scroll = Scrollbar(t, command=text.yview)
text.configure(yscrollcommand=scroll.set)
text.pack(side=LEFT, fill='both', expand=1)
scroll.pack(side=RIGHT, fill=Y)
self.histogram = t

hist = self.current_image.histogram()
for i in range(len(hist)):
msg = "%5d %6d\n" % (i,hist)
text.insert( END, msg )
--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>


Do you mean that the Text widget doesn't let you copy-and-paste copy
its contents using selection and <Control-c>? That shouldn't have
anything to do with the contents of the Text widget.

Whoops, I missed it. I'm not quite sure what I did to make it seem like it
doesn't copy, but it does. I fooled myself. All is well.

--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top