[Tutor] Get user input in wxpython
Kent Johnson
kent37 at tds.net
Sat Aug 6 16:20:54 CEST 2005
_ Dan _ wrote:
> Hi:
> I'm new to python and wxpython, and I'm trying to make
> a program to send mail. I'm using what follows:
> class MyFrame1(wx.Frame):
> def __init__(self, *args, **kwds):
> ...
> self.message = wx.TextCtrl(self.panel_1, -1, "")
> self.button_1 = wx.Button(self.panel_1, -1, "SEND
> Mail")
> ...
> # And then:
> wx.EVT_BUTTON(self,self.button_1.GetId(),
> self.Mail)
>
> # The Mail method is:
> def Mail(self,event):
> self.from = "dquepal at hotmail.com"
> self.host = "localhost"
> self.to = "danf_1979 at yahoo.es"
>
> self.body = self.message
This line is the problem as you might have guessed :-)
self.message is an instance of wx.TextCtrl, not a text string. Try
self.body = self.message.GetValue()
Kent
PS There doesn't seem to be any need to make from, host, to and body be attributes of self; you could use plain local variables here.
>
> server = smtplib.SMTP(self.host)
> server.sendmail(self.from, [self.to],
> self.body)
> server.quit()
>
> But when pressing the Send Mail button I only get:
> TypeError: len() of unsized object
>
> Anybody knows what I'm doing wrong? Maybe I'm not
> getting the user input, or just dont know how to use
> that input in the Mail method...
>
> Because if I use:
> def Mail(self,event):
> self.from = "dquepal at hotmail.com"
> self.host = "localhost"
> self.to = "danf_1979 at yahoo.es"
>
> self.body = "any message" #as string everything
> works fine.
>
> server = smtplib.SMTP(self.host)
> server.sendmail(self.from, [self.to], self.body)
> server.quit()
>
> Thanks in advanced.
> Daniel Queirolo.
>
>
>
>
>
> ______________________________________________
> Renovamos el Correo Yahoo!
> Nuevos servicios, más seguridad
> http://correo.yahoo.es
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list