开发者

wxpython, find control based on its name

I was wondering if it is possible (I'm sure it is) to get a reference to开发者_开发技巧 a control based on the name of the control.

Something like control = findcontrol("btnProduct"+buttonNumber)

You probably catch my drift... (and yes, I am a newby in wxPython)

Regards,

Dennis


You can use the frame instance's FindWindowByName() method, assuming you passed a unique name parameter to the widget or you might be able to use the frame instance's FindWindowByLabel() method. You can also find by id, but I don't really recommend that since it's better not to manage the ids yourself.


In the end I ended up with this:

        control = getattr(self, "btnProduct%s" % (str(buttonNo)))
        control.SetLabel("")

Thanks Mark for steering me in the right direction!


Read up on the python locals() and globals() functions.

For instance you could:

control = locals()['btnProduct' + buttonNumber]

Of course their is probably a much better way to do what you want. Put your controls into a dictionary maybe?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜