#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    44
    Rep Power
    11

    wxPYTHON message dialog


    Code:
    FIRST THE CODE - WxPython:
    
    def On_LOpen(self, event):
            dlg = wxMessageDialog(self, 'Message',
              'Caption', wxYES | wxNO | wxCANCEL | wxICON_INFORMATION)
    
            try:
                if dlg.ShowModal() == wxID_YES:
                    self.txt.WriteText('YES')
                elif dlg.ShowModal() == wxID_NO:
                    self.txt.WriteText('NO')
            finally:
                dlg.Destroy()
            
    	event.Skip()
    I try to test the functionality of a message dialog, if I hit the 'YES' button the textbox(not included here) will display the word 'YES', the 'NO' button will cause the textbox to display 'NO' the 'CANCEL' will close the messagedialog , the 'YES' button works, the 'NO' button also works but in a different way, I have to hit the button twice before the dialog dissapear and the text appear, I can figure out the problem, any idea.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    It is because you are calling dlg.ShowModal() twice. The first time it returns wxID_NO but you are comparing it with wxID_YES, so the test fails. Then you call it again to and compare the result with wxID_NO. What you need to do is call it once and save the result in a variable:

    Code:
    def On_LOpen(self, event):
            dlg = wxMessageDialog(self, 'Message',
              'Caption', wxYES | wxNO | wxCANCEL | wxICON_INFORMATION)
    
            try:
                result = dlg.ShowModal()
                if  result == wxID_YES:
                    self.txt.WriteText('YES')
                elif result == wxID_NO:
                    self.txt.WriteText('NO')
            finally:
                dlg.Destroy()
            
    	event.Skip()
    Dave - The Developers' Coach
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    44
    Rep Power
    11
    Thanks so much man, you've saved me from a very serious head ache

IMN logo majestic logo threadwatch logo seochat tools logo