13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>wxPython</strong> griptshttp://www.zetcode.com/wxpython/gripts/vbox = wx.BoxSizer(wx.VERTICAL)hbox1 = wx.BoxSizer(wx.HORIZONTAL)hbox2 = wx.BoxSizer(wx.HORIZONTAL)hbox3 = wx.BoxSizer(wx.HORIZONTAL)st1 = wx.StaticText(panel, -1, 'From')st2 = wx.StaticText(panel, -1, 'To ')st3 = wx.StaticText(panel, -1, 'Subject')self.tc1 = wx.TextCtrl(panel, -1, size=(180, -1))self.tc2 = wx.TextCtrl(panel, -1, size=(180, -1))self.tc3 = wx.TextCtrl(panel, -1, size=(180, -1))self.write = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE)button_send = wx.Button(panel, 1, 'Send')hbox1.Add(st1, 0, wx.LEFT, 10)hbox1.Add(self.tc1, 0, wx.LEFT, 35)hbox2.Add(st2, 0, wx.LEFT, 10)hbox2.Add(self.tc2, 0, wx.LEFT, 50)hbox3.Add(st3, 0, wx.LEFT, 10)hbox3.Add(self.tc3, 0, wx.LEFT, 20)vbox.Add(hbox1, 0, wx.TOP, 10)vbox.Add(hbox2, 0, wx.TOP, 10)vbox.Add(hbox3, 0, wx.TOP, 10)vbox.Add(self.write, 1, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, 15)vbox.Add(button_send, 0, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 20)self.Bind(wx.EVT_BUTTON, self.OnSend, id=1)panel.SetSizer(vbox)self.Centre()self.ShowModal()self.Destroy()def OnSend(self, event):sender = self.tc1.GetValue()recipient = self.tc2.GetValue()subject = self.tc3.GetValue()text = self.write.GetValue()header = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n' % (sender, recipient, subject)message = header + texttry:server = smtplib.SMTP('mail.chello.sk')server.sendmail(sender, recipient, message)server.quit()dlg = wx.MessageDialog(self, 'Email was successfully sent', 'Success',wx.OK | wx.ICON_INFORMATION)dlg.ShowModal()dlg.Destroy()except smtplib.SMTPException, error:dlg = wx.MessageDialog(self, 'Failed to send email', 'Error', wx.OK | wx.ICON_ERROR)dlg.ShowModal()dlg.Destroy()app = wx.App()Tom(None, -1, 'Tom')app.MainLoop()For working with emails we need to import smtp module. This module is partof the python language.2 de 12 27/04/2008 1:09

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!