0

私はプログラムを書いているので、SMSを電子メールで送信し、wxpythonを使用できます。コンボボックスを使用して、電話番号が関連付けられているキャリアを選択します。ただし、キャリアを選択する機会が得られる前に、プログラムは他のすべてを続行します. 選択するまでこれを停止する方法はありますか? ここでコピー/貼り付けする方法をまだ学習しているので、インデントエラーを許してください。私のコードではすべて正しいです。みんな、ありがとう!:)

  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
4

1 に答える 1

0

すぐにそれself.carrierはタイプであり、メソッドwx.ComboBoxがないことをお伝えできます。ShowModal()そして、もしそうなら、それは戻らないでしょうwx.EVT_COMBOBOX。このShowModal()メソッドは、クリックされたボタンのIDを返します。wx.EVT_COMBOBOXはイベントであり、IDではないため、返されません。

のみwx.Dialogを使用しますShowModal()。必要なダイアログは(ここwx.SingleChoiceDialogにチュートリアルがありますが、7/8ほど下にスクロールする必要があります。または、「singlechoice」を押して検索してください)のように見えます。これにより、リストが表示され、ユーザーに1つの選択を行うように求められます。ctrl+f


または、 (3つの個別のダイアログではなく)1つの便利なダイアログに必要なすべての情報を含む独自のカスタムダイアログ(ここここ のチュートリアル)を作成することもできます。

私はあなたが以下に見つけることができるラフドラフトを書きました。私はそれをテストしていないのでエラーがあるかもしれないことを覚えておいてください、しかしそれはあなたが何をする必要があるかについてあなたに考えを与えるはずです。また、おそらくオブジェクトをサイザーに配置し、レイアウトを希望どおりに整理する必要があります。

class MyTxtMsgDialog (wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent=parent, title="My Txt Message Dialog")

        self.number = wx.TextCtrl(self)
        self.carrier = wx.ComboBox(self, -1, pos=(10, 50), choices=carriers, style=wx.CB_READONLY)
        self.message = wx.TextCtrl(self, style=wx.TC_MULTILINE) #means this TextCtrl will be multiple lines, not just one
        self.okButton = wx.Button(self, wx.ID_OK, "OK")
        #Setting the ID to wx.ID_OK is important. Any of the wx.ID_* variables work natively with ShowModal()
        #but if you created your own ID using the wx.NewId() method then you will need to manually call
        #"self.EndModal(<your ID>)" when your button is clicked.

次に、次を使用して呼び出します。

txtMsgDialog = MyTxtMsgDialog(self)
if txtMsgDialog.ShowModal() == wx.ID_OK: #check to see if OK was pressed
    #save the values
    self.number = txtMsgDialog.number.GetValue()
    self.carrier = txtMsgDialog.carrier.GetGetValue()
    self.message = txtMsgDialog.message.GetValue()

    txtMsgDialog.Destroy() #close the dialog

最後に、私の例でわかるようにDestroy()、ダイアログが終了したら、すべてのダイアログでメソッドを呼び出すことをお勧めします。これにより、それらが閉じられ、リソースが解放されます。ただし、このメソッドを呼び出した後、まだ保存していない変数はすべて失われるため、注意してください。
あなたが電話をかけない理由はDestroy()、あなたが以前に尋ねた質問への答えのためだと思います。これは主にスタイルの問題ですが、他のコメント投稿者は間違っていたと思います。ダイアログが終わったら、ダイアログを破棄する必要があります。ダイアログを閉じ、リソースを解放し、すべてのチュートリアルを作成する方法です。

于 2012-08-15T05:59:08.270 に答える