简体   繁体   English

wxPython-按钮

[英]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. 下方有2个按钮。 They call Rem function: 他们调用Rem函数:

def Rem(self, i):
    print i

I would like to write 'i' from 'posortowane' when I click button. 单击按钮时,我想从“ posortowane”中写“ i”。 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. 但它会在我单击按钮之前调用Rem函数。 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 . 若要传递参数而不立即调用回调,则应使用lambda

self.Bind(wx.EVT_BUTTON, lambda evt, i: self.Rem(evt,i), btn4)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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