[Tutor] Calling Dialog Box from a Class

richard python at keep-trying.com
Wed Jan 28 15:19:17 EST 2004


Folks,

I am attempting when a button is pressed for an OK dialog box to
pop up. Now when I script it directly info the button def. it works
ok. However when I try to put it in a seperate class and then
call it fails. Code is shown below.

         def OnButton1Button(self, event):
                         messagebox.Info('This is a test','This Caption')

class messagebox:
     def Info(self, message,caption):
         dlg = wxMessageDialog(self,message, caption, wxOK | 
wxICON_INFORMATION)
         dlg.ShowModal()
         dlg.Destroy()

Now how I understand it is that I have called my dialog box Info and assigned
it the two attributes message and caption. So when I want to call it from
my button function I should just first describe the class it belongs to 
'messagebox'
then assign Info as the instance which I wish to call followed by the two 
attributes
in brackets which Info require. Up then should pop the button with the relevant
caption and relvent text. However Python disagrees and returns this error:

Traceback (most recent call last):
   File "D:\pythonwork\tesguis\mainmenu.py", line 65, in OnButton1Button
     messagebox.Info('This is a test','This Caption')
TypeError: unbound method Info() must be called with messagebox instance as
first argument (got str instance instead)

Which I do not understand why , when it is the first instance being 
called?? and
why is Info unbound??
I have been reading through the past tutor archives and the most recent thread
on classes some of which confused me further, but this is not making sense.

Any help

Python 2.3, wxwindows.

Thanks,

Richard





More information about the Tutor mailing list