| | |
wxPython Events help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hey guys,
I have made a small program called 'Py-mailer' which allows you to login with your Gmail credentials and send text-only messages to anyone. I uploaded it on SourceForge( http://www.tinyurl.com/m4ans4).
The next step I had to take was to make a GUI for it. So, I started with wxPython:
But, on clicking 'Quit' in the 'File' menu, nothing happens! I think it is because in line 29, I have not passed the ID of the event, so how do I pass the ID? Or, is because of some thing else?
Thanks
I have made a small program called 'Py-mailer' which allows you to login with your Gmail credentials and send text-only messages to anyone. I uploaded it on SourceForge( http://www.tinyurl.com/m4ans4).
The next step I had to take was to make a GUI for it. So, I started with wxPython:
python Syntax (Toggle Plain Text)
import wx window=wx.App() class pymailer(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,"Pymailer",size=(500,500)) panel=wx.Panel(self,-1) menu=wx.MenuBar() items=wx.Menu() items.Append(201,"Quit") self.Bind(wx.EVT_LEFT_DOWN,self.Quit,id=201) menu.Append(items,"File") self.SetMenuBar(menu) wx.StaticText(panel,-1,"Please enter your Gmail login ID: ",pos=(10,10)) wx.StaticText(panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,40)) username=wx.TextCtrl(panel,101,"Login ID",pos=(220,10)) password=wx.TextCtrl(panel,102,"Password",pos=(220,40)) self.Centre() self.Show() def Quit(self,event): self.Close() pymailer() window.MainLoop()
But, on clicking 'Quit' in the 'File' menu, nothing happens! I think it is because in line 29, I have not passed the ID of the event, so how do I pass the ID? Or, is because of some thing else?
Thanks
Change to this.
Python Syntax (Toggle Plain Text)
items.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit,id=201)
I have advanced till here:
But, after entering the login details and clicking on 'Login', nothing happens. Any help?
Thank 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)) panel=wx.Panel(self,-1) menu=wx.MenuBar() items=wx.Menu() items.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit) menu.Append(items,"File") self.SetMenuBar(menu) wx.StaticText(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(panel,-1,"Please enter your Gmail login ID: ",pos=(10,100)) wx.StaticText(panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130)) username=wx.TextCtrl(panel,101,"Login ID",pos=(220,100)) password=wx.TextCtrl(panel,102,"Password",pos=(220,130)) login=wx.Button(panel,103,label="Login",pos=(10,170)) self.Bind(wx.EVT_LEFT_DOWN,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(panel,-1,"Logging in...",pos=(10,200)) s.login(user,passw) except: wx.StaticText(panel,-1,"Failed",pos=(10,220)) pymailer() window.MainLoop()
But, after entering the login details and clicking on 'Login', nothing happens. Any help?
Thank you
What's the difference between
Also, can you explain to me why I should use
EVT_BUTTON and EVT_LEFT_DOWN ?Also, can you explain to me why I should use
self.panel ? Last edited by sravan953; Sep 22nd, 2009 at 11:02 pm. Reason: Type error
•
•
Join Date: Jun 2009
Posts: 23
Reputation:
Solved Threads: 1
EVT_LEFT_DOWN doesn't work because wx.Button doesn't propagate EVT_LEFT_DOWN, it will only propagate wx.EVT_BUTTON. The thing is that objects like Button and ListCtrl will only propagate certain events, not all events. Take a look at the wxpython docs to see what events are used. http://www.wxpython.org/docs/api/wx.Button-class.html
As for using self.panel, in the constructor the variable panel is created, but when the constructor is done, panel is also destroyed. So in the login function, when 'panel' is used it errors because panel was destroyed. Using self.panel will allow access to the variable throughout the class until the class is destroyed. I'm not sure if I'm explaining it well enough, but if there are lots of tutorials, ect. on class structure floating about the web that can help.
Good luck, and I'm looking forward to seeing this in action!
As for using self.panel, in the constructor the variable panel is created, but when the constructor is done, panel is also destroyed. So in the login function, when 'panel' is used it errors because panel was destroyed. Using self.panel will allow access to the variable throughout the class until the class is destroyed. I'm not sure if I'm explaining it well enough, but if there are lots of tutorials, ect. on class structure floating about the web that can help.
Good luck, and I'm looking forward to seeing this in action!
winmic, if I use
If I use
Anyways, this is the code till now:
Also, when I used
Any other bugs in the code?
Thanks
panel , it gives this error:•
•
•
•
Traceback (most recent call last):
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 52, in Login
wx.StaticText(panel,-1,"Failed",pos=(10,220))
NameError: global name 'panel' is not defined
self.panel , it gives this error:•
•
•
•
Traceback (most recent call last):
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 64, in <module>
pymailer()
File "C:\Documents and Settings\Sravan\My Documents\Sravan\PYTHON\GUI.py", line 36, in __init__
login=wx.Button(self.panel,103,label="Login",pos=(10,170))
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,"Pymailer",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) 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(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(panel,-1,"Please enter your Gmail login ID: ",pos=(10,100)) wx.StaticText(panel,-1,"Please enter your Gmail login password:\n(will not be stored)",pos=(10,130)) username=wx.TextCtrl(panel,101,"Login ID",pos=(220,100)) password=wx.TextCtrl(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(panel,-1,"Logging in...",pos=(10,200)) s.login(user,passw) except: wx.StaticText(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()
Also, when I used
self.panel , I replaced panel with self.panel everywhere, just thought I'd let you know!Any other bugs in the code?
Thanks
Last edited by sravan953; Sep 23rd, 2009 at 6:09 am. Reason: Mistake
![]() |
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 advanced advice ajax anydbm applet arax beginner c++ class code console convert coordinates corners csv curves custom customdialog dictionary draw dynamic dynamically event examples excel exe failwhale file filename function google gui hints images input ip jaunty java launcher linux list listener lists module mouse movingimageswithpygame multiple mysqldb mysqlquery newb numbers opensource path print program programming projects py-mailer py2exe pygame python rails random raw_input read recursion recursive redirect return reverse ruby server simple software sqlite ssh string strings table text thread threading time tkinter tricks tutorial ubuntu unicode urllib urllib2 variable verify voip whileloop windows wordgame write wxpython






