wxGlade

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pilu

    wxGlade

    hi,given that I'm a newbie in python,
    I have a little problem with wx...
    Maybe it's a stupid thing,but if u want help me!
    I used wxglade to generate a simple window with a button!
    wxglade generates the code,and now I try to insert events,but I have an
    error,I don't understand!
    The code is this:

    from wxPython.wx import *

    class MyFrame(wxFrame ):
    def __init__(self, *args, **kwds):
    # begin wxGlade: MyFrame.__init_ _
    kwds["style"] = wxDEFAULT_FRAME _STYLE
    wxFrame.__init_ _(self, *args, **kwds)
    self.button_1 = wxButton(self, -1, "button_1")

    self.__set_prop erties()
    self.__do_layou t()
    # end wxGlade
    EVT_BUTTON(self , 1003, self.event)

    def __set_propertie s(self):
    # begin wxGlade: MyFrame.__set_p roperties
    self.SetTitle(" frame_1")
    # end wxGlade

    def __do_layout(sel f):
    # begin wxGlade: MyFrame.__do_la yout
    sizer_1 = wxBoxSizer(wxVE RTICAL)
    sizer_1.Add(sel f.button_1, 0, 0, 0)
    self.SetAutoLay out(1)
    self.SetSizer(s izer_1)
    sizer_1.Fit(sel f)
    sizer_1.SetSize Hints(self)
    self.Layout()
    # end wxGlade
    def event(self):
    print "ciao"

    # end of class MyFrame


    class MyApp(wxApp):
    def OnInit(self):
    frame = MyFrame(NULL, -1, "Hello from wxPython")
    frame.Show(true )
    self.SetTopWind ow(frame)
    return true

    app = MyApp(0)
    app.MainLoop()





    Thanks
    -pilu-
  • Markus Faltin

    #2
    Re: wxGlade

    I'm a newbie regarding wxPython, nevertheless I worked this out:
    [color=blue]
    > class MyFrame(wxFrame ):
    > def __init__(self, *args, **kwds):
    > # begin wxGlade: MyFrame.__init_ _
    > kwds["style"] = wxDEFAULT_FRAME _STYLE
    > wxFrame.__init_ _(self, *args, **kwds)
    > self.button_1 = wxButton(self, -1, "button_1")
    > self.__set_prop erties()
    > self.__do_layou t()
    > # end wxGlade
    > EVT_BUTTON(self , 1003, self.event)[/color]

    You have to set the identifier of the button:
    self.button_1 = wxButton(self, 1003, "button_1")
    [color=blue]
    > def event(self):
    > print "ciao"[/color]

    The triggered method also needs the event as a parameter:

    def event(self, event):
    print "ciao"


    Markus

    Comment

    • Brian Kelley

      #3
      Re: wxGlade

      Markus Faltin wrote:[color=blue]
      > I'm a newbie regarding wxPython, nevertheless I worked this out:
      >
      >[color=green]
      >>class MyFrame(wxFrame ):
      >> def __init__(self, *args, **kwds):
      >> # begin wxGlade: MyFrame.__init_ _
      >> kwds["style"] = wxDEFAULT_FRAME _STYLE
      >> wxFrame.__init_ _(self, *args, **kwds)
      >> self.button_1 = wxButton(self, -1, "button_1")
      >> self.__set_prop erties()
      >> self.__do_layou t()
      >> # end wxGlade
      >> EVT_BUTTON(self , 1003, self.event)[/color]
      >
      >
      > You have to set the identifier of the button:
      > self.button_1 = wxButton(self, 1003, "button_1")[/color]

      Not necessarily, you can keep the -1 designation and then
      EVT_BUTTON(self , self.button_1.G etId(), self.event)

      I prefer this method since it is less book keeping for me.

      Brian Kelley

      Comment

      Working...