在wxpython中,您不能禁用/启用sizer及其项,因此我决定遍历sizer并逐个禁用它们。
我的面板看起来如下:
vertical_sizer
├── horizontal_sizer_1
│ └── dynamic_created_elements
└── horizontal_sizer_2
└── dynamic_created_elements因为我的项目是动态创建的,所以我不知道里面有多少种元素,也不知道是什么类型的元素,所以不能通过他们的id来完成。所以我有这个密码:
for horizontal_sizer in self.my_sizer.GetChildren():
for element in horizontal_sizer.GetChildren():
element.Enable()但是我一直在我的horizontal_sizer上得到错误的horizontal_sizer。
发布于 2017-11-22 19:57:40
您应该尝试对您的GetWindow()项调用horizontal_sizer,并将其打印出来,以确定它是None还是您没有预料到的小部件。我的怀疑是,您的垂直sizer中有另一个小部件,它不是一个sizer。
或者,您可以使用Python的hasattr来确定子项是否有GetChildren()作为方法,如果没有,只需跳过它:
for horizontal_sizer in self.my_sizer.GetChildren():
if hasattr(horizontal_sizer, 'GetChildren'):
for element in horizontal_sizer.GetChildren():
element.Enable() https://stackoverflow.com/questions/47434464
复制相似问题