如何迭代所有 wx.CheckBox 实例?
我有一个 wx 框架,其中有很多复选框。当用户经常更改下拉菜单(wx.ComboBox)中的设置时,我想清除所有复选框。目前,我已经实现了一个方法,当 ComboBox 发生更改时会调用该方法,并且它会手动清除每个复选框,即:
def ClearCheckBoxes(self):
self.cb_EnableControl.SetValue(0)
self.cb_EnableRun.SetValue(0)
self.cb_EnablePower.SetValue(0)
...
...
虽然我只有大约 10 个复选框,但如果是这样的,我的 ClearCheckBoxes 方法会更干净:
def ClearCheckBoxes(self):
for CheckBox in self.AllCheckBoxes:
CheckBox.SetValue(0)
另外,我想我可以创建一个列表(即AllCheckBoxes
)并在创建它们时将所有复选框添加到列表中,然后只需迭代列表即可。但这里的重点是我想知道是否有一种预定义的方法可以做到这一点。
谢谢
I have a wx frame where I have a quite a few checkboxes. Ever so often when the user changes the settings in a drop down menu (wx.ComboBox) I'd like to clear all the checkboxes. Currently, I've implemented a method that gets called when a change in the ComboBox happens and it clears each check box manually, i.e.:
def ClearCheckBoxes(self):
self.cb_EnableControl.SetValue(0)
self.cb_EnableRun.SetValue(0)
self.cb_EnablePower.SetValue(0)
...
...
Although I only have about 10 of these, my ClearCheckBoxes method would be much cleaner if it were something like this:
def ClearCheckBoxes(self):
for CheckBox in self.AllCheckBoxes:
CheckBox.SetValue(0)
Also, I suppose I could create a list (i.e. AllCheckBoxes
) and add all the checkboxes to the list as I create them, and then it would only be a matter of iterating through the list. But the point here is that I'd like to know if there was an pre-defined way of doing this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有没有尝试过一些超级丑陋的东西,比如:
Have you tried something super ugly like: