Re: [Tutor] Tkinter, how to retrieve information about an object on canvas

2012-11-17 Thread Axel Wegen
Matheus Soares da Silva  writes:
> Hello, I would like to be able to get information from a Tkinter
> canvas object. (color, width, tags, root points, etc),
You can get the information of an object on the canvas by passing its id
to certain canvas methods like itemconfigure:

>>> c = Canvas()
>>> c.pack()
>>> c.create_rectangle(30,30,90,90,fill="black")
1
>>> c.itemconfigure(1)

Should yield a dictionary containing the options of the rectangle.

> the widget is returned as a tuple by the find_overlapping method.
Utilising find_overlapping you will get a tuple of multiple object-ids.
To get a single object you index into the tuple:

>>> c.find_overlapping(31,31,33,33)
(1,)
>>> c.itemconfigure(c.find_overlapping(31,31,33,33)[0])


btw. there is also a tkinter specific mailing-list:
tkinter-disc...@python.org

--
Axel Wegen
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pygame problem with mac

2012-11-17 Thread Ciaran Mooney
Hi,

Was hoping u could help me. 

I can't seem to download a version of pygame that is compatible with python 3.2 
on my Mac powerbook with OS tiger. 

I only seem to he able to get pygame for python 2.7 which i have never used. 

Thanks
Ciaran


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Quick question about definitions.

2012-11-17 Thread sillywilly98
I know this code is not fully debugged. I just cant see why 1 definition is
wrong.  
Here is the code:
# This program draws a robot.

from turtle import *

def draw_eyes():
# This function
penup()
color("purple")
goto(-50, 200)
pendown()
begin_fill()
circle(20)
end_fill()
penup()
goto(50, 200)
begin_fill()
circle(20)
end_fill(()

def draw_nose():
# This function 
penup()
color("orange")
goto(0, 150)
pendown()
begin_fill()
circle(20, steps=3)
end_fill(()

def draw_mouth():
# This function
penup()
color("pink"
goto(-50, 100)
pendown()
begin_fill()
forward(100)
right(90)
forward(20)
right(90)
forward(100)
right(90)
forward((20)
right(90)
end_fill()

def draw_head():
# This function
draw_eyes()
draw_nose()
draw_mouth()
penup()
color("blackk")
goto(-100, 50
pendown()
goto(100, 50)
goto(100, 275)
goto(-100, 275)
gto(-100, 50)

def draw_panel():
# This function
penup()
color("grey")
width(4)
goto(-75, 0)
pendown()
goto(75, 0)
goto(75, -100)
goto(-75, -100)
goto(-75, 0)
penup()
clor("red")
goto(-25, -50)
pendown()
circle25, steps=3)
penup()
color("green")
goto(25, -50)
pendown()
rght(180)
circle(25, steps=3)
right(180)

def draw_arm():
# This function
pendown()
color("black")
width(2)
right(90")
forward(150)
right(90)
forward(25)
color("red")
begin_fill()
circle(50)
end_fill()
color("black")
forward(25)
right(90)
forward(150)
right(90)
forward(50)

def draw_body():
# This function
draw_panel()
penup()
color("black")
width(1))
goto(-150, 50)
pendown()
goto(150, 50)
goto(150, -250)
goto(-150, -250)
goto(-150, 50)
draw_arm()
penupp()
goto(200, 50)
draw_arm()

draw_head()
draw_body()

exitonclick)





--
View this message in context: 
http://python.6.n6.nabble.com/Quick-question-about-definitions-tp4996080.html
Sent from the Python - tutor mailing list archive at Nabble.com.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Adding a gifting option too basic shipping page

2012-11-17 Thread Elizabeth Balderston
Hi-

I'm attempting to use Python in order to set up a basic shipping order
page. After having figured out thee page along with email confirmation, I
 realized that I had forgotten a gift option that would automatically
affect the price if checked.

I have no idea how to add this feature to my program or if it will change
the whole thing so I have to start from scratch. If you could help me with
creating this, that would be amazing.

Thank you so much,
Liz
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] New to Python - simple question

2012-11-17 Thread Unaiza Ahsan
Hi all,

I am following Jan Erik Solem's book "Programming Computer Vision with
Python" and I'm just on the first chapter. The book asked us to create a
file imtools.py and put down helpful functions there, which we can just
call later.

There is a function created for histogram equalization of images (called *
histeq*), and saved in imtools.py. When I use this function and type this
in IDLE:
>>> from PIL import Image
>>> from numpy import *
>>> im = array(Image.open('Tulips.jpg').convert('L'))
>>> im2,cdf = imtools.histeq(im)

I get this:

Traceback (most recent call last):
  File "", line 1, in 
im2,cdf = imtools.histeq(im)
  File "C:\Python27\imtools.py", line 18, in histeq
imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
NameError: global name 'histogram' is not defined

And the relevant portion in imtools.py is:
def histeq(im,nbr_bins=256):
""" Histogram equalization of a grayscale image. """

#get image histogram
imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
cdf = imhist.cumsum() #Cumulative distribution function
cdf = 255* cdf/cdf[-1] #Normalize

#Use linear interpolation of cdf to find new pixel values
im2 = interp(im.flatten(), bins[:-1],cdf)

return im2.reshape(im.shape), cdf


Can anybody point out where I'm going wrong? I have Python 2.7, NumPY,
SciPY etc.

Thanks very much

Python Newbie!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python - simple question

2012-11-17 Thread staticsafe
On 11/16/2012 12:40, Unaiza Ahsan wrote:
> Hi all,
> 
> I am following Jan Erik Solem's book "Programming Computer Vision with
> Python" and I'm just on the first chapter. The book asked us to create a
> file imtools.py and put down helpful functions there, which we can just
> call later.
> 
> There is a function created for histogram equalization of images (called *
> histeq*), and saved in imtools.py. When I use this function and type this
> in IDLE:
 from PIL import Image
 from numpy import *
 im = array(Image.open('Tulips.jpg').convert('L'))
 im2,cdf = imtools.histeq(im)
> 
> I get this:
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> im2,cdf = imtools.histeq(im)
>   File "C:\Python27\imtools.py", line 18, in histeq
> imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
> NameError: global name 'histogram' is not defined
> 
> And the relevant portion in imtools.py is:
> def histeq(im,nbr_bins=256):
> """ Histogram equalization of a grayscale image. """
> 
> #get image histogram
> imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
> cdf = imhist.cumsum() #Cumulative distribution function
> cdf = 255* cdf/cdf[-1] #Normalize
> 
> #Use linear interpolation of cdf to find new pixel values
> im2 = interp(im.flatten(), bins[:-1],cdf)
> 
> return im2.reshape(im.shape), cdf
> 
> 
> Can anybody point out where I'm going wrong? I have Python 2.7, NumPY,
> SciPY etc.
> 
> Thanks very much
> 
> Python Newbie!

Where is the histogram() function from? Is it in imtools.py as well?
-- 
staticsafe
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Please don't top post - http://goo.gl/YrmAb
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick question about definitions.

2012-11-17 Thread eryksun
On Fri, Nov 16, 2012 at 12:28 PM, sillywilly98  wrote:
>
> I know this code is not fully debugged. I just cant see why 1 definition is
> wrong. 

You have several typos (there may be more):

draw_eyes:
end_fill(()

draw_nose:
end_fill(()

draw_mouth:
color("pink"
forward((20)

draw_head:
color("blackk")
goto(-100, 50
gto(-100, 50)

draw_panel:
clor("red")
circle25, steps=3)
rght(180)

draw_arm:
right(90")

draw_body:
width(1))
penupp()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick question about definitions.

2012-11-17 Thread Dave Angel
On 11/16/2012 12:28 PM, sillywilly98 wrote:
> I know this code is not fully debugged. I just cant see why 1 definition is
> wrong.  
> Here is the code:
> # This program draws a robot.
>
> from turtle import *
>
> def draw_eyes():
> # This function
> penup()
> color("purple")
> goto(-50, 200)
> pendown()
> begin_fill()
> circle(20)
> end_fill()
> penup()
> goto(50, 200)
> begin_fill()
> circle(20)
> end_fill(()
The call to end_fil has unmatched parentheses.  That means the
expression continues on the next line.  But def is a keyword and not
valid inside an expression.

def draw_nose():
# This function 
penup()
color("orange")
goto(0, 150)
pendown()
begin_fill()
circle(20, steps=3)
end_fill(()

Same here.  But in general, once you fix one error, you can spot the next one 
more easily. 





-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Adding a gifting option too basic shipping page

2012-11-17 Thread Alan Gauld

On 10/11/12 19:48, Elizabeth Balderston wrote:


I'm attempting to use Python in order to set up a basic shipping order
page.


OK, I'll assume that you mean you are building a web app rather than a 
desktop?

If so which web framework are you using, if any?


I  realized that I had forgotten a gift option that would automatically
affect the price if checked.

I have no idea how to add this feature to my program or if it will
change the whole thing so I have to start from scratch.


And with no idea of what your design is like or which framework you are 
using neither does anyone else. This is a mailing list for folks 
learning to program with Python. Its focus is on Python itself and the 
standard library.


You question is probably more related ton the web framework you are 
using and as such is better answered by their forum.


However, even there, much will depend on how you have structured your 
application. Are you using a templating system to separate the web page 
design from the code? Are you using a database, and if so are you 
accessing it via an object-relational wrapper? Is it an MVC framework?
Without knowing any of that we can only make the wildest guesses about 
your solution.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python - simple question

2012-11-17 Thread Alan Gauld

On 16/11/12 17:40, Unaiza Ahsan wrote:


There is a function created for histogram equalization of images (called
*histeq*), and saved in imtools.py.




from PIL import Image
from numpy import *
im = array(Image.open('Tulips.jpg').convert('L'))
im2,cdf = imtools.histeq(im)


I get this:

Traceback (most recent call last):
 im2,cdf = imtools.histeq(im)
   File "C:\Python27\imtools.py", line 18, in histeq
 imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
NameError: global name 'histogram' is not defined


This tells us that the name histogram is not defined
in the imtools.py file. Is it one of the modules ytou show imported 
above? If so it will not be visible inside imtools.py. You need to 
import the required module in that file too.


But that's just a guess...


And the relevant portion in imtools.py is:
def histeq(im,nbr_bins=256):
 """ Histogram equalization of a grayscale image. """

 #get image histogram
 imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)


This is the call, but where is histogram? If it is in imtools are you 
sure the spelling is correct? If its not there you need to import it 
from wherever it is defined.


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick question about definitions.

2012-11-17 Thread Steven D'Aprano

On 17/11/12 04:28, sillywilly98 wrote:

I know this code is not fully debugged. I just cant see why 1 definition is
wrong.


Please don't send screen shots if you don't need to. In this case, the screen
shot adds nothing, and turns this into a "long question" instead of a "quick
question".

When you try to run the code, Python will print an error message as text,
which you can easily copy and paste into your email. You should get something
like this:

Traceback (most recent call last):
  File "", line 1, in 
  File "test.py", line 20
def draw_nose():
  ^
SyntaxError: invalid syntax



That is MUCH quicker and simpler than:

* take a screen shot
* crop it
* save it to a file
* upload it to nabble.com
* copy the URL
* send the URL in an email
* hope that people will click on the url
* and that nabble isn't blocked for them (many people can receive email
  but have all or parts of the web blocked)
* hope that they can guess what editor you are using
* hope that they can guess why the editor has coloured "def" red
* or yellow-grey-brown, if they are colour-blind[1]

In this case, the solution is simple: the previous line to the def
is missing the closing parenthesis:

end_fill(()

Unfortunately, when there is a missing bracket of any type, whether
round ), square ] or brace }, the Python interpreter cannot tell it
is missing until it reaches the *next* line. So often when you have
a SyntaxError, it is on the line after the line with the actual
problem.





[1] Software developers: if your software uses colour *alone* to
represent information, you are doing it wrong. About 8% of men
and 0.5% of women have red-green colour-blindness, with other
forms being less common. All up, about 1 in 10 men and 1 in 100
women cannot easily or at all distinguish colours.

http://en.wikipedia.org/wiki/Colour_blindness


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python - simple question

2012-11-17 Thread Kal Sze
On 18 November 2012 07:40, Alan Gauld  wrote:
> On 16/11/12 17:40, Unaiza Ahsan wrote:
>
>> There is a function created for histogram equalization of images (called
>> *histeq*), and saved in imtools.py.
>
>
>
> from PIL import Image
> from numpy import *
> im = array(Image.open('Tulips.jpg').convert('L'))
> im2,cdf = imtools.histeq(im)
>>
>>
>> I get this:
>>
>> Traceback (most recent call last):
>>  im2,cdf = imtools.histeq(im)
>>File "C:\Python27\imtools.py", line 18, in histeq
>>  imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
>> NameError: global name 'histogram' is not defined
>
>
> This tells us that the name histogram is not defined
> in the imtools.py file. Is it one of the modules ytou show imported above?
> If so it will not be visible inside imtools.py. You need to import the
> required module in that file too.
>
> But that's just a guess...
>
>
>> And the relevant portion in imtools.py is:
>> def histeq(im,nbr_bins=256):
>>  """ Histogram equalization of a grayscale image. """
>>
>>  #get image histogram
>>  imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
>
>
> This is the call, but where is histogram? If it is in imtools are you sure
> the spelling is correct? If its not there you need to import it from
> wherever it is defined.
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Hi all,

The function histogram is supposed to come from the numpy module; at
least that's the case on my computer (I have numpy 1.6.2 for Python
2.7):

>>> from numpy import *
>>> histogram


Maybe something is wrong with Unaiza's version of numpy.

Kal
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sending email via smtplib

2012-11-17 Thread Saad Javed
import smtplib

from_addr = "some_a...@hotmail.com"
to_addr = "some_a...@gmail.com"
smtp_srv = "smtp.live.com"

subject = "Test"
message = "Test"

msg = "To:%s\nFrom:%s\nSubject: %s\n\n%s" % (to_addr, from_addr, subject,
message)

smtp = smtplib.SMTP(smtp_srv, 587)
smtp.set_debuglevel(1)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(user, passwd)
smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()

When I run this code, I get this output:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-BLU0-SMTP190.blu0.hotmail.com Hello [my-ip-address]\r\n'
reply: '250-TURN\r\n'
reply: '250-SIZE 41943040\r\n'
reply: '250-ETRN\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-DSN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8bitmime\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250-CHUNKING\r\n'
reply: '250-VRFY\r\n'
reply: '250-TLS\r\n'
reply: '250-STARTTLS\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: BLU0-SMTP190.blu0.hotmail.com Hello
[my-ip-address]
TURN
SIZE 41943040
ETRN
PIPELINING
DSN
ENHANCEDSTATUSCODES
8bitmime
BINARYMIME
CHUNKING
VRFY
TLS
STARTTLS
OK
send: 'STARTTLS\r\n'
Traceback (most recent call last):
  File "sendemail.py", line 24, in 
smtp.starttls()
  File "/usr/lib/python2.7/smtplib.py", line 636, in starttls
(resp, reply) = self.docmd("STARTTLS")
  File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
return self.getreply()
  File "/usr/lib/python2.7/smtplib.py", line 358, in getreply
+ str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104]
Connection reset by peer

I can send email via browser. Why is my authentication being blocked by
hotmail?

P.S: I tried sending from gmail. Same error.

Saad
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor