| | |
wxPython text overwrite problem...
Thread Solved |
Hey All,
I have some code here, the problem is in line 82-83:
- because once I login successfully, if I again login with wrong details, the "Failed" text doesn't overwrite the "Logged in..." text fully.... so what do I do?
Thanks a load
I have some code here, the problem is in line 82-83:
python Syntax (Toggle Plain Text)
import smtplib import wx window=wx.App() class pymailer(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700)) try: self.s=smtplib.SMTP("smtp.gmail.com",587) self.s.starttls() except: wx.MessageBox("Error 001: Could not connect to the internet, please try again later.","Internet Connection Error") self.panel=wx.Panel(self,-1) menubar=wx.MenuBar() filem=wx.Menu() filem.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit,id=201) viewm=wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=202) menubar.Append(filem,"File") menubar.Append(viewm,"Help") self.SetMenuBar(menubar) wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\n\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10)) wx.StaticText(self.panel,-1,"Please enter your Gmail login ID: ",pos=(10,100)) wx.StaticText(self.panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130)) self.username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100)) self.password=wx.TextCtrl(self.panel,102,"Password",style=(wx.TE_PASSWORD),pos=(220,130)) login=wx.Button(self.panel,103,label="Login",pos=(10,170)) self.Bind(wx.EVT_BUTTON,self.Login,id=103) wx.StaticText(self.panel,-1,"To:",pos=(10,250)) wx.StaticText(self.panel,-1,"Subject:",pos=(10,280)) wx.StaticText(self.panel,-1,"Message:",pos=(10,310)) self.to_info=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20)) self.sub_info=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20)) self.msg_info=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150)) send=wx.Button(self.panel,107,"Send",pos=(245,470)) self.Bind(wx.EVT_BUTTON,self.Send,id=107) self.Centre() self.Show() def Quit(self,event): self.Close() def About(self,event): about=wx.AboutDialogInfo() about.SetName("Py-Mailer") about.SetCopyright("(c) 2009 Sravan") about.SetWebSite("http://www.uberpix.wordpress.com") about.AddDeveloper("Sravan") about.AddDeveloper("Daniel Pacheco") wx.AboutBox(about) def Login(self,event): self.user=self.username.GetValue() self.passw=self.password.GetValue() if(self.user=="" and self.passw==""): wx.MessageBox("Error 002: You did not enter your username and/or password","Enter Login Details") try: self.s.login(self.user,self.passw) wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200)) except: wx.StaticText(self.panel,-1,"Failed",pos=(10,200)) def Send(self,event): self.to=self.to_info.GetValue() self.subject=self.sub_info.GetValue() self.message=self.msg_info.GetValue() self.msg="To: "+self.to+"\nSubject: "+self.subject+"\n"+self.message self.s.sendmail(self.user,self.to,self.msg) self.s.quit() wx.StaticText(self.panel,-1,"Your message has been sent!",pos=(175,500)) pymailer() window.MainLoop()
Thanks a load
Last edited by sravan953; 31 Days Ago at 1:15 pm.
0
#2 31 Days Ago
How about instead of just generating an arbitrary StaticText object, assign it to a persistent member of your class (let's call it
self.login_status_text ). Then instead of generating it each time, simply update the contents to the proper string (It's been years since messing with wxPython but if I remember correctly you might want to use SetLabel in this case). •
•
Join Date: Aug 2008
Posts: 148
Reputation:
Solved Threads: 46
0
#3 31 Days Ago
You can set size so the text get overwrite.
And som color look better.
For me i have to have this put in this lines or it dont work for me.
And your design need some work,can give som tips later if you want that.
And som color look better.
Python Syntax (Toggle Plain Text)
try: self.s.login(self.user,self.passw) wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200),size = (150,20)).SetForegroundColour('blue') except: wx.StaticText(self.panel,-1,"Failed",pos=(10,200),size = (150,20)).SetForegroundColour('red')
For me i have to have this put in this lines or it dont work for me.
Python Syntax (Toggle Plain Text)
self.s.ehlo() self.s.starttls() self.s.ehlo()
Last edited by snippsat; 31 Days Ago at 3:08 pm.
0
#4 31 Days Ago
•
•
•
•
You can set size so the text get overwrite.
And som color look better.
Python Syntax (Toggle Plain Text)
try: self.s.login(self.user,self.passw) wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200),size = (150,20)).SetForegroundColour('blue') except: wx.StaticText(self.panel,-1,"Failed",pos=(10,200),size = (150,20)).SetForegroundColour('red')
For me i have to have this put in this lines or it dont work for me.
And your design need some work,can give som tips later if you want that.Python Syntax (Toggle Plain Text)
self.s.ehlo() self.s.starttls() self.s.ehlo()
0
#5 31 Days Ago
•
•
•
•
How about instead of just generating an arbitrary StaticText object, assign it to a persistent member of your class (let's call it self.login_status_text ). Then instead of generating it each time, simply update the contents to the proper string (It's been years since messing with wxPython but if I remember correctly you might want to use SetLabel in this case). 'python Syntax (Toggle Plain Text)
try: self.s.login(self.user,self.passw) self.loginmsg.SetLabel("Logged in...") except: self.loginmsg.SetLabel("Failed to login, please try again...")
But it still doesn't overwrite properly... guess I will just have to settle on snippsat's opinion...
•
•
Join Date: Aug 2008
Posts: 148
Reputation:
Solved Threads: 46
0
#6 30 Days Ago
Hi here are som changes.
Done some work on this,i was thinking making somthing simelar as this for fun.
So helping you a little is no problem,set my self as co-developer in about box if you dont mind.
Here are changes.
----------| Change log |---------
* Change on size and design | New headerpicture
* Take away maximize window (wx.MINIMIZE_BOX)
* Ico for Frame and about box
* New about box style
* Picture buttons
* Bigger message Box and multiline enable(wx.TE_MULTILINE)
* Exception handling on mail sent with new StaticText message
* Better documentation of code
----------| idèe for future development |--------
* Email attachment(file)
* Contact list load
* Save default login
http://www.esnips.com/doc/c2e05e06-5...05ed/py-mailer
Done some work on this,i was thinking making somthing simelar as this for fun.
So helping you a little is no problem,set my self as co-developer in about box if you dont mind.
Here are changes.
----------| Change log |---------
* Change on size and design | New headerpicture
* Take away maximize window (wx.MINIMIZE_BOX)
* Ico for Frame and about box
* New about box style
* Picture buttons
* Bigger message Box and multiline enable(wx.TE_MULTILINE)
* Exception handling on mail sent with new StaticText message
* Better documentation of code
----------| idèe for future development |--------
* Email attachment(file)
* Contact list load
* Save default login
http://www.esnips.com/doc/c2e05e06-5...05ed/py-mailer
Python Syntax (Toggle Plain Text)
import smtplib import time import os import wx from wx.lib.wordwrap import wordwrap window = wx.App() class pymailer(wx.Frame): ''' Program to send gmail message ''' def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY,"Py-mailer",size=(330,520), style = wx.DEFAULT_DIALOG_STYLE | wx.MINIMIZE_BOX) #----| Window color |---# self.SetBackgroundColour("#d8d8bf") #---| Add a panel so it looks the correct on all platforms |---# self.panel = wx.Panel(self, wx.ID_ANY) #---| Ico for window |---# ico = wx.Icon('email1.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(ico) #----| Gmail server |---# self.info = {} self.s = smtplib.SMTP("smtp.gmail.com",587) self.s.ehlo() self.s.starttls() self.s.ehlo() #---| Menu bar |---# menubar=wx.MenuBar() filem=wx.Menu() filem.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit,id=201) viewm = wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=202) menubar.Append(filem,"File") menubar.Append(viewm,"Help") self.SetMenuBar(menubar) #---| Picture Buttons |---# self.send = wx.BitmapButton(self.panel,107,wx.Bitmap("py_email1.png"), pos = (7,430), size = (65,26)) self.Bind(wx.EVT_BUTTON,self.Send,id = 107) self.login = wx.BitmapButton(self.panel,103,wx.Bitmap("py_email2.png"), pos = (7,123), size = (65,26)) self.Bind(wx.EVT_BUTTON,self.Login,id = 103) #---| Standar Buttons |---# #login = wx.Button(self.panel,103,label = "Login", pos = (10,120)) #self.Bind(wx.EVT_BUTTON,self.Login,id = 103) #send = wx.Button(self.panel, 107, "Send", pos = (50,400)) #self.Bind(wx.EVT_BUTTON, self.Send,id = 107) #---| Picture |---# self.bitmap_1 = wx.StaticBitmap(self, -1, wx.Bitmap("py1.png", wx.BITMAP_TYPE_ANY),pos = (43,5 ), size = (250,42)) #---| Label Text |---# wx.StaticText(self, -1, '---------------------------------------------------------------------------', pos = (10,107), size = (400,13 )).SetForegroundColour('blue') wx.StaticText(self, -1, '---------------------------------------------------------------------------', pos = (10,35), size = (400,13 )).SetForegroundColour('blue') wx.StaticText(self, -1, '---------------------------------------------------------------------------', pos = (10,150), size = (400,13 )).SetForegroundColour('blue') #wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10)) wx.StaticText(self.panel,-1,"Enter your Gmail login ID: ",pos = (10,55)) wx.StaticText(self.panel,-1,"Enter your Gmail password:\n(will not be stored)",pos = (10,80)) wx.StaticText(self.panel,-1,"To:",pos = (10,180)) wx.StaticText(self.panel,-1,"Subject:",pos = (10,210)) wx.StaticText(self.panel,-1,"Message",pos = (135,240)).SetForegroundColour('brown') #----| TextBox |---# self.username = wx.TextCtrl(self.panel,101,"tomlaa1@gmail.com",pos = (150,50),size = (160,20)) self.password = wx.TextCtrl(self.panel,102,"qqqqqq11",style = (wx.TE_PASSWORD), pos = (150,80),size = (160,20)) self.to_info = wx.TextCtrl(self.panel,104,pos = (70,180),size = (240,20)) self.sbj_info = wx.TextCtrl(self.panel,105,pos = (70,210),size = (240,20)) self.msg_info = wx.TextCtrl(self.panel,106,style = wx.TE_MULTILINE,pos = (13,265),size = (300,150)) self.Centre() self.Show() def Quit(self,event): self.Close() def Login(self,event): self.user=self.username.GetValue() self.passw=self.password.GetValue() try: self.s.login(self.user,self.passw) wx.StaticText(self.panel,-1,"You are logged in...",pos = (130,127)).SetForegroundColour('blue') except: wx.StaticText(self.panel,-1,"Login in failed",pos = (100,125)).SetForegroundColour('red') def Send(self,event): self.info["To"] = self.to_info.GetValue() self.info["Subject"] = self.sbj_info.GetValue() self.info["Message"]= self.msg_info.GetValue() self.to=self.info["To"] self.subject = self.info["Subject"] self.message = self.info["Message"] self.msg = "To: " + self.to + "\nSubject: " + self.subject+"\n" + self.message try: self.s.sendmail(self.user,self.to,self.msg) wx.StaticText(self.panel,-1,"Mail send successfully",pos = (120,435)).SetForegroundColour('blue') self.s.quit() except: wx.StaticText(self.panel,-1,"Mail not sent",pos = (120,435)).SetForegroundColour('red') def About(self,event): ''' Show about window ''' info = wx.AboutDialogInfo() info.Name = "Py-Mailer" info.Version = "version ?" info.Copyright = "" info.Description = wordwrap( 'info about this program......' , 350, wx.ClientDC(self)) info.WebSite = ("http://www.uberpix.wordpress.com", "Sravan home") info.Developers = [ "Dan Sravan\n" 'Co-developer:\n' 'Snippsat',] info.License = wordwrap(licenseText, 500, wx.ClientDC(self)) wx.AboutBox(info) licenseText = 'Copyright(c) 2009 Sravan' pymailer() window.MainLoop()
Last edited by snippsat; 30 Days Ago at 7:11 pm.
•
•
•
•
Hi here are som changes.
Done some work on this,i was thinking making somthing simelar as this for fun.
So helping you a little is no problem,set my self as co-developer in about box if you dont mind.
Here are changes.
----------| Change log |---------
* Change on size and design | New headerpicture
* Take away maximize window (wx.MINIMIZE_BOX)
* Ico for Frame and about box
* New about box style
* Picture buttons
* Bigger message Box and multiline enable(wx.TE_MULTILINE)
* Exception handling on mail sent with new StaticText message
* Better documentation of code
----------| idèe for future development |--------
* Email attachment(file)
* Contact list load
* Save default login
http://www.esnips.com/doc/c2e05e06-5...05ed/py-mailer
Python Syntax (Toggle Plain Text)
import smtplib import time import os import wx from wx.lib.wordwrap import wordwrap window = wx.App() class pymailer(wx.Frame): ''' Program to send gmail message ''' def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY,"Py-mailer",size=(330,520), style = wx.DEFAULT_DIALOG_STYLE | wx.MINIMIZE_BOX) #----| Window color |---# self.SetBackgroundColour("#d8d8bf") #---| Add a panel so it looks the correct on all platforms |---# self.panel = wx.Panel(self, wx.ID_ANY) #---| Ico for window |---# ico = wx.Icon('email1.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(ico) #----| Gmail server |---# self.info = {} self.s = smtplib.SMTP("smtp.gmail.com",587) self.s.ehlo() self.s.starttls() self.s.ehlo() #---| Menu bar |---# menubar=wx.MenuBar() filem=wx.Menu() filem.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit,id=201) viewm = wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=202) menubar.Append(filem,"File") menubar.Append(viewm,"Help") self.SetMenuBar(menubar) #---| Picture Buttons |---# self.send = wx.BitmapButton(self.panel,107,wx.Bitmap("py_email1.png"), pos = (7,430), size = (65,26)) self.Bind(wx.EVT_BUTTON,self.Send,id = 107) self.login = wx.BitmapButton(self.panel,103,wx.Bitmap("py_email2.png"), pos = (7,123), size = (65,26)) self.Bind(wx.EVT_BUTTON,self.Login,id = 103) #---| Standar Buttons |---# #login = wx.Button(self.panel,103,label = "Login", pos = (10,120)) #self.Bind(wx.EVT_BUTTON,self.Login,id = 103) #send = wx.Button(self.panel, 107, "Send", pos = (50,400)) #self.Bind(wx.EVT_BUTTON, self.Send,id = 107) #---| Picture |---# self.bitmap_1 = wx.StaticBitmap(self, -1, wx.Bitmap("py1.png", wx.BITMAP_TYPE_ANY),pos = (43,5 ), size = (250,42)) #---| Label Text |---# wx.StaticText(self, -1, '---------------------------------------------------------------------------', pos = (10,107), size = (400,13 )).SetForegroundColour('blue') wx.StaticText(self, -1, '---------------------------------------------------------------------------', pos = (10,35), size = (400,13 )).SetForegroundColour('blue') wx.StaticText(self, -1, '---------------------------------------------------------------------------', pos = (10,150), size = (400,13 )).SetForegroundColour('blue') #wx.StaticText(self.panel,-1,"Welcome to Py-mailer.\nLogin with your Gmail credentials and you can send a text-only email to anyone quickly and easily.",pos=(10,10)) wx.StaticText(self.panel,-1,"Enter your Gmail login ID: ",pos = (10,55)) wx.StaticText(self.panel,-1,"Enter your Gmail password:\n(will not be stored)",pos = (10,80)) wx.StaticText(self.panel,-1,"To:",pos = (10,180)) wx.StaticText(self.panel,-1,"Subject:",pos = (10,210)) wx.StaticText(self.panel,-1,"Message",pos = (135,240)).SetForegroundColour('brown') #----| TextBox |---# self.username = wx.TextCtrl(self.panel,101,"tomlaa1@gmail.com",pos = (150,50),size = (160,20)) self.password = wx.TextCtrl(self.panel,102,"qqqqqq11",style = (wx.TE_PASSWORD), pos = (150,80),size = (160,20)) self.to_info = wx.TextCtrl(self.panel,104,pos = (70,180),size = (240,20)) self.sbj_info = wx.TextCtrl(self.panel,105,pos = (70,210),size = (240,20)) self.msg_info = wx.TextCtrl(self.panel,106,style = wx.TE_MULTILINE,pos = (13,265),size = (300,150)) self.Centre() self.Show() def Quit(self,event): self.Close() def Login(self,event): self.user=self.username.GetValue() self.passw=self.password.GetValue() try: self.s.login(self.user,self.passw) wx.StaticText(self.panel,-1,"You are logged in...",pos = (130,127)).SetForegroundColour('blue') except: wx.StaticText(self.panel,-1,"Login in failed",pos = (100,125)).SetForegroundColour('red') def Send(self,event): self.info["To"] = self.to_info.GetValue() self.info["Subject"] = self.sbj_info.GetValue() self.info["Message"]= self.msg_info.GetValue() self.to=self.info["To"] self.subject = self.info["Subject"] self.message = self.info["Message"] self.msg = "To: " + self.to + "\nSubject: " + self.subject+"\n" + self.message try: self.s.sendmail(self.user,self.to,self.msg) wx.StaticText(self.panel,-1,"Mail send successfully",pos = (120,435)).SetForegroundColour('blue') self.s.quit() except: wx.StaticText(self.panel,-1,"Mail not sent",pos = (120,435)).SetForegroundColour('red') def About(self,event): ''' Show about window ''' info = wx.AboutDialogInfo() info.Name = "Py-Mailer" info.Version = "version ?" info.Copyright = "" info.Description = wordwrap( 'info about this program......' , 350, wx.ClientDC(self)) info.WebSite = ("http://www.uberpix.wordpress.com", "Sravan home") info.Developers = [ "Dan Sravan\n" 'Co-developer:\n' 'Snippsat',] info.License = wordwrap(licenseText, 500, wx.ClientDC(self)) wx.AboutBox(info) licenseText = 'Copyright(c) 2009 Sravan' pymailer() window.MainLoop()
•
•
Join Date: Aug 2008
Posts: 148
Reputation:
Solved Threads: 46
0
#8 27 Days Ago
•
•
•
•
How did you make those images?
Thats just screenshot capture with free program jing.
http://www.jingproject.com/
•
•
Join Date: Nov 2009
Posts: 79
Reputation:
Solved Threads: 21
0
#9 26 Days Ago
Note that the way you use try/except is not very wise.
You should do something like this instead:
Python Syntax (Toggle Plain Text)
try: self.s.sendmail(self.user,self.to,self.msg) wx.StaticText(self.panel,-1,"Mail send successfully",pos = (120,435)).SetForegroundColour('blue') self.s.quit() except: wx.StaticText(self.panel,-1,"Mail not sent",pos = (120,435)).SetForegroundColour('red')
Python Syntax (Toggle Plain Text)
try: self.s.sendmail(self.user,self.to,self.msg) except LoginError: wx.StaticText(self.panel,-1,"Mail not sent",pos = (120,435)).SetForegroundColour('red') else: wx.StaticText(self.panel,-1,"Mail send successfully",pos = (120,435)).SetForegroundColour('blue') self.s.quit()
![]() |
Similar Threads
- wxpython text colours (Python)
- 40 Column Text Mode problem (C)
- text pad problem (C++)
- Pygame text.render problem - printing variables (Python)
- Expandable Javascript Text Block Problem (JavaScript / DHTML / AJAX)
- HELP: Tkinter Text Widget problem (Python)
- video card / internet problem (Monitors, Displays and Video Cards)
- wxPython Error while running. (Python)
Other Threads in the Python Forum
- Previous Thread: Find largest file in directory
- Next Thread: Reasons to extend Python with C
| Thread Tools | Search this Thread |







