| | |
wxPython Events help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 23
Reputation:
Solved Threads: 1
This is the code that I have working, not exactly sure why self.panel wouldn't work for you.
Python Syntax (Toggle Plain Text)
import smtplib import time import os import wx window=wx.App() class pymailer(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,"Pymailer",size=(500,500)) self.panel=wx.Panel(self,-1) menubar=wx.MenuBar() filem=wx.Menu() filem.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit) viewm=wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About) menubar.Append(filem,"File") menubar.Append(viewm,"Help") self.SetMenuBar(menubar) 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,"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)) username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100)) password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130)) login=wx.Button(self.panel,103,label="Login",pos=(10,170)) self.Bind(wx.EVT_BUTTON,self.Login) self.Centre() self.Show() def Quit(self,event): self.Close() def Login(self,event): s=smtplib.SMTP("smtp.gmail.com",587) s.starttls() try: wx.StaticText(self.panel,-1,"Logging in...",pos=(10,200)) s.login(user,passw) except: wx.StaticText(self.panel,-1,"Failed",pos=(10,220)) 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\nDan") wx.AboutBox(about) pymailer() window.MainLoop()
Hmm...I too don't know why
Now, what should I do to make a button(called 'Next>'), which on being clicked will 'refresh' the screen and display some new contents? I hope you understand me!
self.panel isn't working. I will get back to you about that.Now, what should I do to make a button(called 'Next>'), which on being clicked will 'refresh' the screen and display some new contents? I hope you understand me!
Last edited by sravan953; Sep 23rd, 2009 at 10:40 am.
•
•
Join Date: Jun 2009
Posts: 23
Reputation:
Solved Threads: 1
So I forgot something with events, you can make them respond to a certain id. If you have tried to File->Quit recently you'll see that it will make the about:dialog appear. If you have objects that propagate the same event then you'll want them id specific. so self.Bind(wx.EVT_MENU,self.Quit) becomes self.Bind(wx.EVT_MENU,self.Quit, id=201). The same thing will need to be done for the about menu event, and if you add another button the button event will need to be id specific.
How to add new content really depends on specifically what you want to do. I'm guessing that you want to have completely new content where all old content is destroyed, then you would probably want to create a new wx.Panel and content. I could help a little more if you were a little more specific.
BTW, have you thought about how your going to get the username and password out of the TextCtrl?
How to add new content really depends on specifically what you want to do. I'm guessing that you want to have completely new content where all old content is destroyed, then you would probably want to create a new wx.Panel and content. I could help a little more if you were a little more specific.
BTW, have you thought about how your going to get the username and password out of the TextCtrl?
Last edited by winmic; Sep 23rd, 2009 at 2:08 pm. Reason: new question
•
•
•
•
BTW, have you thought about how your going to get the username and password out of the TextCtrl?
http://www.wxpython.org/docs/api/wx.TextCtrl-class.html
One of the functon is GetValue() that returns a string of the value in the textctrl, simple
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
I don't think getting the values will be a problem, because I've heard of GetValues() and Google it for help.
The problem is: the
One more question:
-but it doesn't work. How do I specify the ID when defining the function?
Thanks
The problem is: the
self.panel doesn't at all work...One more question:
python Syntax (Toggle Plain Text)
viewm=wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=302) def About(self,event,id=302): about=wx.AboutDialogInfo()
Thanks
•
•
•
•
I don't think getting the values will be a problem, because I've heard of GetValues() and Google it for help.
The problem is: theself.paneldoesn't at all work...
One more question:
-but it doesn't work. How do I specify the ID when defining the function?python Syntax (Toggle Plain Text)
viewm=wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=302) def About(self,event,id=302): about=wx.AboutDialogInfo()
Thanks
self.panel will work if you use it throughout the class! Search for 'panel' with your editor.
drink her pretty
•
•
•
•
You don't need the id as a method parameter, but at least try to match the id in the lines above, 202 is not the same as 302.
self.panel will work if you use it throughout the class! Search for 'panel' with your editor.
'python Syntax (Toggle Plain Text)
viewm=wx.Menu() viewm.Append(202,"About") self.Bind(wx.EVT_MENU,self.About,id=202) def About(self,event): about=wx.AboutDialogInfo()
But, only "Quit" works, and "About" doesn't.
Also, if I use [icode]self.panel[icode] throughout, it says:
Here's the modified code including [icode]self.panel[icode]everywhere
•
•
•
•
Traceback (most recent call last):
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 72, in <module>
pymailer()
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 29, in __init__
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))
AttributeError: 'pymailer' object has no attribute 'panel'
python Syntax (Toggle Plain Text)
import smtplib import time import os import wx window=wx.App() class pymailer(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,500)) 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.\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)) username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100)) password=wx.TextCtrl(self.panel,102,"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,220)) wx.StaticText(self.panel,-1,"Subject:",pos=(10,250)) wx.StaticText(self.panel,-1,"Message:",pos=(10,280)) to=wx.TextCtrl(self.panel,103,"<username@domain.server>",pos=(80,220),size=(240,20)) subject=wx.TextCtrl(self.panel,104,pos=(80,250),size=(240,20)) message=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,150)) self.Centre() self.Show() def Quit(self,event): self.Close() def About(self,event): about=wx.AboutDialogInfo() def Login(self,event,): wx.StaticText(panel,-1,"Logging in...",pos=(10,200)) s=smtplib.SMTP("smtp.gmail.com",587) s.starttls() try: s.login(user,passw) except: wx.StaticText(self.panel,-1,"Failed",pos=(10,200)) about.SetName("Py-Mailer") about.SetCopyright("(c) 2009 Sravan") about.SetWebSite("http://www.uberpix.wordpress.com") about.AddDeveloper("Sravan\nDan") wx.AboutBox(about) pymailer() window.MainLoop()
Till now:
No matter what I enter, it doesn't login and says "Failed". Why?
Also, how do I mask the password input?
python Syntax (Toggle Plain Text)
import smtplib import time import os import wx window=wx.App() s=smtplib.SMTP("smtp.gmail.com",587) s.starttls() class pymailer(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,"Py-mailer",size=(500,700)) 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.\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)) username=wx.TextCtrl(self.panel,101,"Login ID",pos=(220,100)) user=username.GetValue() password=wx.TextCtrl(self.panel,102,"Password",pos=(220,130)) passw=password.GetValue() 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)) toadd=wx.TextCtrl(self.panel,104,"<username@domain.server>",pos=(80,250),size=(240,20)) to=toadd.GetValue() subj=wx.TextCtrl(self.panel,105,pos=(80,280),size=(240,20)) subject=subj.GetValue() mess=wx.TextCtrl(self.panel,106,pos=(80,310),size=(240,150)) message=mess.GetValue() 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\nDan") wx.AboutBox(about) def Login(self,event): try: s.login(user,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): msg="To: "+to+"\nSubject: "+subject+"\n"+message s.sendmail(us,to,msg) s.quit() pymailer() window.MainLoop()
No matter what I enter, it doesn't login and says "Failed". Why?
Also, how do I mask the password input?
![]() |
Similar Threads
- Starting wxPython (GUI code) (Python)
- wxPython Events!!!!!!!!???? (Python)
- wxPython: wx.RadioButtons SetValue has no affect in Linux (Python)
- Help Needed with wxPython Configuration (Python)
- wxPython Event Handler (Python)
Other Threads in the Python Forum
- Previous Thread: saving variables to a file in python
- Next Thread: My program (major flaws in it)
| Thread Tools | Search this Thread |
Tag cloud for event, leftmouse, python, wxpython
accessdenied address advice ajax anti anydbm applet arax avogadro beginner bluetooth c++ class code console convert coordinates copy csv cturtle dan08 def draw dynamic edit enter event examples excel exe file filename function google gui halp handler images input jaunty java keyboard launcher linux list lists loan maze michaeljackson module movingimageswithpygame multiple mysql numbers parameters path program programming projects push py py2exe pygame pygtk pysimplewizard python rails random raw_input read recursive redirect return reverse ruby signal simple sqlite statictext string strings sum table thread threading time tkinter tutorial twitter ubuntu unicode update urllib urllib2 variable ventrilo web-scrape windows write wxpython







