|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Thanks so much man, you've saved me from a very serious head ache
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > wxPYTHON message dialog |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|