How to I get pressed button ID ?

fowlertrainer writes:
Some code:

      self.MainButtons=
     self.MainBtnNames=("How Many / Last Week - sheets","Diagrams","Other
reports","Exit")
      self.MainSizer=wxBoxSizer(wxVERTICAL)
      cnt=1;l=len(self.MainBtnNames)
      for s in self.MainBtnNames:
          btnid=1200+cnt
          if (cnt==l): btnid=1200
          b=wxButton(self,btnid,s)
          b.SetBackgroundColour(wxColour(40, 136, 216))
          if btnid==1200: self.MainSizer.Add(b,1,wxALL|wxEXPAND,8)
          else: self.MainSizer.Add(b,1,wxALL|wxEXPAND,8)
          EVT_BUTTON(self,btnid,self.OnClickBtn)
          self.MainButtons.append(b)
          cnt=cnt+1
def OnClickBtn(self,e):
   print e.???

I want to get the ID of button to do the needed thing.

I must use this form, because more and more buttons needed, and I don't
want to write the same code time to time.

So: how can I get this ID ?

And how can I set the mainform to the center of the screen ?

Thanx.

F

···

fowlertrainer writes:

Some code:

      self.MainButtons=
     self.MainBtnNames=("How Many / Last Week -
sheets","Diagrams","Other
reports","Exit")
      self.MainSizer=wxBoxSizer(wxVERTICAL)
      cnt=1;l=len(self.MainBtnNames)
      for s in self.MainBtnNames:
          btnid=1200+cnt
          if (cnt==l): btnid=1200
          b=wxButton(self,btnid,s)
          b.SetBackgroundColour(wxColour(40, 136, 216))
          if btnid==1200:
self.MainSizer.Add(b,1,wxALL|wxEXPAND,8)
          else:
self.MainSizer.Add(b,1,wxALL|wxEXPAND,8)
          EVT_BUTTON(self,btnid,self.OnClickBtn)
          self.MainButtons.append(b)
          cnt=cnt+1
def OnClickBtn(self,e):
   print e.???

I want to get the ID of button to do the needed thing.

I must use this form, because more and more buttons needed, and I
don't want to write the same code time to time.

So: how can I get this ID ?

Try this:

    def OnClickBtn(self,event):
        print event.GetEventObject().GetId()

···

=====
Donnal Walter
Arkansas Children's Hospital

fowlertrainer wrote:

And how can I set the mainform to the center of the screen ?

  frame.CenterOnScreen()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Donnal Walter wrote:

fowlertrainer writes:

So: how can I get this ID ?

Try this:

    def OnClickBtn(self,event):
        print event.GetEventObject().GetId()

  event.GetId() should be the correct ID too.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!