2.7.9: PhotoImage get/put

Emile van Sebille emile at fenx.com
Tue Oct 20 18:25:14 EDT 2015


On 10/20/2015 3:05 PM, Randy Day wrote:
> I'm writing a simple image manipulation
> on a PhotoImage (tkinter), and running
> into an odd problem. The code below works,
> except for one thing:
>
> As the image is scanned, I'd like to
> observe the pixels getting inverted on
> the image (as a kind of progress bar).
> What happens is that the code runs the
> complete loop before refreshing the
> photo.

I have no idea why, but here are some ideas I'd try out.

So is it refreshing upon completion of the loop, or upon exit from 
process()?

What happens if you put an outer loop around yours to process hght in 
ten (pick a number) steps?

Emile


> I've tried various forms of
> refresh(), update(), etc., within the
> loop, but so far no luck. Am I
> missing something simple?
>
> def process(): # Ordinarily this would be process(photo,wdth,hgt)
>    global wdth # but I ran into problems calling it from a button
>    global hgt  #command with parameters...
>    global photo # the PhotoImage displayed by the calling code
>
> # indents set to 1 to avoid word wrap
>
> # Loop through rows and columns of the image
>    v=wdth
>    z=0
>    a=-1
>    for y in range (0,hgt):
>      w=v
>      v=z # swap v and z so rows are scanned l/r r/l l/r
>      z=w
>      a=-a # set our inc/dec step for lr->rl scan
>
>      for x in range(v,z,a):
>       pix = photo.get(x,y) if pix == u'0 0 0' :
>       #pixel_turn_on()
>       photo.put("#%02x%02x%02x" % (255,255,255), (x,y)) 	
>      else:
>       #pixel_turn_off()
>       photo.put("#%02x%02x%02x" % (0,0,0), (x,y))
>
> --- news://freenews.netfront.net/ - complaints: news at netfront.net ---
>





More information about the Python-list mailing list