PIL implementation

C

circusdei

I wrote this snippet with the intention of -- capturing a section of
the screen whenever it changes. It could be implemented to log any
sort of messaging system ( by saving consecutive images eg.
1.png...etc).

#code --------------------

import Image
import ImageGrab
lastchatbound = (21, 504) + (189, 516)
img1 = ImageGrab.grab(lastchatbound)
data1 = list(img1.getdata())
img2 = ImageGrab.grab(lastchatbound)
data2 = list(img2.getdata())
# print `data1`
if data1 != data2:
img1.save(`picnumber` + '.png')
picnumber = picnumber + 1
else:
print "same"

#code ------------------

it doesn't work yet and i'm not quite sure how the loops work yet ( i
just sarted python last week). any help anyone could give me would be
appreciated.

if someone could rewrite it so it works, i could use that as an example
for the future, thanks.

- mb
 
C

Claudio Grondi

circusdei said:
I wrote this snippet with the intention of -- capturing a section of
the screen whenever it changes. It could be implemented to log any
sort of messaging system ( by saving consecutive images eg.
1.png...etc).

#code --------------------

import Image
import ImageGrab
lastchatbound = (21, 504) + (189, 516)
img1 = ImageGrab.grab(lastchatbound)
data1 = list(img1.getdata())
img2 = ImageGrab.grab(lastchatbound)
data2 = list(img2.getdata())
# print `data1` pictnumber = 0
if data1 != data2:
img1.save(`picnumber` + '.png')
picnumber = picnumber + 1
else:
print "same"

#code ------------------

it doesn't work yet and i'm not quite sure how the loops work yet ( i
just sarted python last week). any help anyone could give me would be
appreciated.

if someone could rewrite it so it works, i could use that as an example
for the future, thanks.

- mb
At the first glance the code looks almost ok. It is a good habit always
to attach documentation of the error messages if any.
What I can directly see is, that you need at least to initialize the
picnumber (see above).
Look in the Python documentation for the chapter with loops, read about
the time module you will need to let the loop pause before taking the
next screenshot and consider also, that maybe later it would be a good
idea to have a way to stop the loop executing.
Come back with the next revision of your code for further help if you
get into trouble or wait until someone else provides you with
appropriate working code.

Claudio
 
A

arkestra

The error message is --> "Syntax error" and it highlights the last
"else" statement.
 
A

arkestra

The error message is --> "Syntax error" and it highlights the last
"else" statement.

thanks for the reply.
 
P

Peter Hansen

arkestra said:
The error message is --> "Syntax error" and it highlights the last
"else" statement.

You've got incorrect indentation, at least judging by what I see in my
newsreader (Thunderbird), which clearly shows the else indented more
than the corresponding if.

Next time, please cut and paste the *actual* error message instead of
retyping and paraphrasing. That will get you a faster answer and save
us lots of annoying guessing.
 

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

No members online now.

Forum statistics

Threads
474,276
Messages
2,571,384
Members
48,072
Latest member
FaustoBust

Latest Threads

Top