I’m writing a program so I can send SMS via email and using wxpython. Using Combobox to select which carrier the phone number is attached to. However, the program continues with everything else before I have a chance to select a carrier. Is there a way to make this halt until I make a choice? Still learning how to copy/paste in here so forgive any indentation errors, it’s all correct in my code. Thanks everyone! 🙂
if password.ShowModal() == wx.ID_OK:
pwd =password.GetValue()
phone_number = wx.TextEntryDialog(self,"Phone Number", "Phone Number", "")
if phone_number.ShowModal() == wx.ID_OK:
number = phone_number.GetValue()
self.carrier = wx.ComboBox(self, -1, pos=(10, 50), choices=carriers, style=wx.CB_READONLY)
self.carrier.Bind(wx.EVT_COMBOBOX, self.onCombo)
if self.carrier.ShowModal() == wx.EVT_COMBOBOX:
message = wx.TextEntryDialog(self,"Your Message", "Your Message", "")
if message.ShowModal() == wx.ID_OK:
msg = message.GetValue()
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(username, pwd)
header = 'To:' + email + '\n' + 'From: ' + username + '\n' + 'Subject:testing \n'
print header
msg1 = header + msg
smtpserver.sendmail(username, email, msg1)
smtpserver.close()
def onCombo(self, event):
self.selection = self.carrier.GetValue()
print self.selection
print self.number
self.email = number + selection
print email
return self.email
Right away I can tell you that
self.carrieris of typewx.ComboBoxand does not have aShowModal()method. And if it did it wouldn’t returnwx.EVT_COMBOBOX. TheShowModal()method returns the ID of the button that was clicked.wx.EVT_COMBOBOXis an event, not an ID and thus would not be returned.Only
wx.Dialogs useShowModal(). It looks like the dialog you want is awx.SingleChoiceDialog(You can find a tutorial here but you’ll need to scroll about 7/8 of the way down. Or just hitctrl+fand search for “singlechoice”). This will show a list and prompt users to make a single selection.Alternatively, you could create your own custom dialog (tutorials here and here) that contain all the information you need in a single convenient dialog (instead of three separate ones).
I wrote rough draft that you can find below. Just remember that I haven’t tested it so there may be errors, but it should give you an idea of what you need to do. Also, you should probably place the objects in a sizer and organize the layout the way you want it.
You’d then call it using:
One final note: as you can see in my example, it’s a good idea to call theDestroy()method on all of your dialogs when you’re done with them. This will close them and free the resources. Be careful though because after you call this method any variables you didn’t already save will be gone.I see the reason you aren’t calling
Destroy()is because of an answer to a question you asked previously. It’s mostly a style issue but I think that other commenter was wrong and you should destory your dialogs when you are done with them. It closes the dialog, frees up your resources, and it’s the way all the tutorials are written.