简体   繁体   中英

wxPython - button

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM