0

Here is my code:

for i in posortowane:
    z += 20
    result = '%s: %s' % (i[0], i[1])
    wx.StaticText(panel, -1, result, (345, 125 + z), style=wx.ALIGN_CENTRE)
    btn4 = wx.Button(panel, -1, u"Remove", (485, 120 + z))
    self.Bind(wx.EVT_BUTTON, self.Rem, btn4)

There are 2 buttons one below the other. They call Rem function:

def Rem(self, i):
    print i

I would like to write 'i' from 'posortowane' when I click button. It doesn't work. I tried:

self.Bind(wx.EVT_BUTTON, self.Rem(i), btn4)

but it calls Rem function before I click a button. How can I achieve this? I am sorry for my english. Thank you for any help.

jundymek
  • 1,013
  • 4
  • 18
  • 40
  • You are saying there are 2 buttons, but there is only one button created in the code. It would help the investigation if you could post more code. – Quinn Apr 02 '16 at 00:52
  • I would like to add a button to every line in my program (it would be "name" and "delete" button next to it. I am trying to add settings to my program (using json). Program counts how many times in ms excell file "name" exists - name - 24, name1 - 46, name2 - 121 e.t.c. Names are strored in json file. I would like to add/remove names. I am not able to ask you what I want because of my poor english... – jundymek Apr 03 '16 at 18:54

1 Answers1

2

When you add paranthesis, you are telling interpreter to call that function right away.
To pass parameters without calling callback immediatly, you should use lambda.

self.Bind(wx.EVT_BUTTON, lambda evt, i: self.Rem(evt,i), btn4)
Lafexlos
  • 7,618
  • 5
  • 38
  • 53