Попробуй так:
import wx, smtplib
import sys as _sys
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 200))
panel = wx.Panel(self)
btn = wx.Button(panel, -1, “Close”)
funbtn = wx.Button(panel, -1, “Send”)
self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(btn, 0, wx.ALL, 10)
sizer.Add(funbtn, 0, wx.ALL, 10)
panel.SetSizer(sizer)
panel.Layout()
def OnTimeToClose(self, evt):
self.Close()
def OnFunButton(self, evt):
fromaddr = “From:
zzz@zzz.zzz”
toaddrs = “To:
aaa@aaa.aaa”
msg = ‘Test message’
print “Message length is %d” % len(msg)
server = smtplib.SMTP('smtp.zzz.zzz')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, “Simple wxPython App”)
self.SetTopWindow(frame)
print “Print statements go to this stdout window by default.”
frame.Show(True)
return True
def RedirectStdio(self, filename=None):
if filename:
_sys.stdout = _sys.stderr = smtplib.stderr = open(filename, ‘a’)
else:
self.stdioWin = self.outputWindowClass()
_sys.stdout = _sys.stderr = smtplib.stderr = self.stdioWin
app = MyApp(redirect=True)
app.MainLoop()
%) столько ещё интересных идей есть…