wxPython按钮

2024-10-16 17:16:25 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:

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)

有两个按钮,一个在另一个下面。它们称为Rem函数:

def Rem(self, i):
    print i

当我点击按钮时,我想从“posortowane”写“I”。它不起作用。我试过:

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

但它在我点击按钮之前调用Rem函数。我怎样才能做到这一点?我为我的英语感到抱歉。谢谢你的帮助。你知道吗


Tags: 函数inself密码forbindbuttonresult
1条回答
网友
1楼 · 发布于 2024-10-16 17:16:25

当您添加paranthesis时,您告诉解释器立即调用该函数。
要传递参数而不立即调用回调,应该使用^{}。你知道吗

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

相关问题 更多 >