Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97846 > unrolled thread
| Started by | Randy Day <randy.day@sasktel.netx> |
|---|---|
| First post | 2015-10-20 16:05 -0600 |
| Last post | 2015-10-21 09:31 -0600 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.python
2.7.9: PhotoImage get/put Randy Day <randy.day@sasktel.netx> - 2015-10-20 16:05 -0600
Re: 2.7.9: PhotoImage get/put Emile van Sebille <emile@fenx.com> - 2015-10-20 15:25 -0700
Re: 2.7.9: PhotoImage get/put Randy Day <randy.day@sasktel.netx> - 2015-10-20 23:59 -0600
Re: 2.7.9: PhotoImage get/put C Smith <illusiontechniques@gmail.com> - 2015-10-20 18:44 -0700
Re: 2.7.9: PhotoImage get/put Randy Day <randy.day@sasktel.netx> - 2015-10-20 23:50 -0600
Re: 2.7.9: PhotoImage get/put Terry Reedy <tjreedy@udel.edu> - 2015-10-21 03:51 -0400
Re: 2.7.9: PhotoImage get/put Randy Day <randy.day@sasktel.netx> - 2015-10-21 09:31 -0600
| From | Randy Day <randy.day@sasktel.netx> |
|---|---|
| Date | 2015-10-20 16:05 -0600 |
| Subject | 2.7.9: PhotoImage get/put |
| Message-ID | <MPG.309076b1693d9388989686@freenews.netfront.net> |
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'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@netfront.net ---
[toc] | [next] | [standalone]
| From | Emile van Sebille <emile@fenx.com> |
|---|---|
| Date | 2015-10-20 15:25 -0700 |
| Message-ID | <mailman.63.1445379941.878.python-list@python.org> |
| In reply to | #97846 |
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@netfront.net ---
>
[toc] | [prev] | [next] | [standalone]
| From | Randy Day <randy.day@sasktel.netx> |
|---|---|
| Date | 2015-10-20 23:59 -0600 |
| Message-ID | <MPG.3090e5a812828e89989688@freenews.netfront.net> |
| In reply to | #97847 |
In article <mailman.63.1445379941.878.python-list@python.org>, emile@fenx.com says... [snip] > 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()? It turns out I need to call root.update_idletasks() for my root Tk object to get it to refresh after I put the pixel. It works great now. --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | C Smith <illusiontechniques@gmail.com> |
|---|---|
| Date | 2015-10-20 18:44 -0700 |
| Message-ID | <mailman.66.1445391898.878.python-list@python.org> |
| In reply to | #97846 |
>> def process(): # Ordinarily this would be process(photo,wdth,hgt)
>> global wdth # but I ran into problems calling it from a button
If you want to pass arguments to a command called when a button is
clicked, you have to use 'lambda' in tkinter.
>> 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))
You can't expect a delay to happen during the mainloop() of the
program. To interrupt the mainloop(), use: parent.after(n,someCommand)
Where 'n' is some amount of milliseconds. Just have the parent widget
or the root frame call it.
[toc] | [prev] | [next] | [standalone]
| From | Randy Day <randy.day@sasktel.netx> |
|---|---|
| Date | 2015-10-20 23:50 -0600 |
| Message-ID | <MPG.3090e3b0778a0d9c989687@freenews.netfront.net> |
| In reply to | #97851 |
In article <mailman.66.1445391898.878.python-list@python.org>, illusiontechniques@gmail.com says... [snip] > If you want to pass arguments to a command called when a button is > clicked, you have to use 'lambda' in tkinter. Thanks. I just skimmed over lambda before now... > You can't expect a delay to happen during the mainloop() of the > program. To interrupt the mainloop(), use: parent.after(n,someCommand) > Where 'n' is some amount of milliseconds. Just have the parent widget > or the root frame call it. When I read your post, I realized I'm doing a crude animation. After a bit of searching on 'python canvas animation', I found a reference to how it's done: I made my 'root' Tk instance global, and call root.update_idletasks() after the .put It works great! Now back to the lambdas (Ralph the Wonder Lambda, Earl J Lambda, Mike Q Lambda III, et al?). --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2015-10-21 03:51 -0400 |
| Message-ID | <mailman.71.1445413916.878.python-list@python.org> |
| In reply to | #97854 |
On 10/21/2015 1:50 AM, Randy Day wrote: > When I read your post, I realized I'm doing > a crude animation. After a bit of searching > on 'python canvas animation', I found a > reference to how it's done: > > I made my 'root' Tk instance global, and > call root.update_idletasks() after the > .put I did not see the original post, but the alternative way to animate is to use root.after(milliseconds, callback, *args) at the end of callbacks to allow the event loop to process other events before re-calling the same or another callback. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Randy Day <randy.day@sasktel.netx> |
|---|---|
| Date | 2015-10-21 09:31 -0600 |
| Message-ID | <MPG.30916bbcab389c7d989689@freenews.netfront.net> |
| In reply to | #97859 |
In article <mailman.71.1445413916.878.python-list@python.org>, tjreedy@udel.edu says... [snip] > > I made my 'root' Tk instance global, and > > call root.update_idletasks() after the > > .put > I did not see the original post, but the alternative way to animate is > to use root.after(milliseconds, callback, *args) at the end of callbacks > to allow the event loop to process other events before re-calling the > same or another callback. I could see that being useful for creating a steady frame rate in longer animations. I'll put that one in my Python toolbox as well. --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web