Hi all,
I'm new to python, and I'm stuck in this problem: I cannot understand
why this code doesn't work:
(the pattern's from wxPyWiki. I'm stumped...and I guess a little hint
could do a lot for me)
from wxPython.wx import *
class MyFrame(wxFrame):
class MyButton(wxButton):
def __init__(self, parent, label, id , x, y, whotocall):
wxButton.__init__ ( self, parent, id, label, wxPoint(x, y),
wxDefaultSize, 1 )
self.whotocall = whotocall
EVT_BUTTON ( self, id, self.OnClick )
def OnClick ( self, event ):
if self.whotocall:
self.whotocall()
print 'OnClick'
print event
def OnMyButton(self, text):
self.codice.SetLabel(text)
self.pannello_output.Show(True)
def __init__(self):
wxFrame.__init__(self, None, -1, 'title', pos=wxPoint(0, 3),
size=wxSize(1016, 735), style=wxDEFAULT_FRAME_STYLE)
self.panel1 = wxPanel(id=-1, name='panel1', parent=self,
pos=wxPoint(8, 400), size=wxSize(170, 320), style=wxTAB_TRAVERSAL)
self.panel1.SetBackgroundColour(wxColour(216, 216, 191))
self.pannello_output = wxPanel(id=-1, name='pannello_output',
parent=self, pos=wxPoint(193, 405),size=wxSize(300, 313),
style=wxTAB_TRAVERSAL)
self.pannello_output.SetBackgroundColour(wxColour(216, 216,
171))
self.pannello_output.Show(False)
self.codice = wxStaticText(id=-1, label='', name='codice',
parent=self.pannello_output, pos=wxPoint(5, 0),size=wxSize(262, 21),
style=wxSTATIC_BORDER | wxALIGN_CENTRE | 1)
b1 = self.MyButton(self.panel1, 'test', -1, 80, 20,
self.OnMyButton('test'))
if __name__ == '__main__':
app = wxPySimpleApp()
frame = MyFrame()
frame.Show(true)
app.MainLoop()
------------------and this one works:
from wxPython.wx import *
class MyFrame(wxFrame):
class MyButton(wxButton):
def __init__(self, parent, label, id , x, y, whotocall):
wxButton.__init__ ( self, parent, id, label, wxPoint(x, y),
wxDefaultSize, 1 )
self.whotocall = whotocall
EVT_BUTTON ( self, id, self.OnClick )
def OnClick ( self, event ):
if self.whotocall:
self.whotocall ( )
print 'OnClick'
print event
def OnMyButton(self):
self.codice.SetLabel('test')
self.pannello_output.Show(True)
def __init__(self):
wxFrame.__init__(self, None, -1, 'title', pos=wxPoint(0, 3),
size=wxSize(1016, 735), style=wxDEFAULT_FRAME_STYLE)
self.panel1 = wxPanel(id=-1, name='panel1', parent=self,
pos=wxPoint(8, 400), size=wxSize(170, 320), style=wxTAB_TRAVERSAL)
self.panel1.SetBackgroundColour(wxColour(216, 216, 191))
self.pannello_output = wxPanel(id=-1, name='pannello_output',
parent=self, pos=wxPoint(193, 405),size=wxSize(300, 313),
style=wxTAB_TRAVERSAL)
self.pannello_output.SetBackgroundColour(wxColour(216, 216,
171))
self.pannello_output.Show(False)
self.codice = wxStaticText(id=-1, label='', name='codice',
parent=self.pannello_output, pos=wxPoint(5, 0),size=wxSize(262, 21),
style=wxSTATIC_BORDER | wxALIGN_CENTRE | 1)
b1 = self.MyButton(self.panel1, 'test', -1, 80, 20,
self.OnMyButton)
if __name__ == '__main__':
app = wxPySimpleApp()
frame = MyFrame()
frame.Show(true)
app.MainLoop()
thanks in advance,
-fc