wxpython 按钮 禁用_wxPython:禁用多个按钮

下面是一个有效的例子:"""

Demonstration on how to disable / enable all objects within a sizer

Reinhard Daemon / Austria

08.10.2019

"""

import wx

class MainWindow(wx.Frame):

def __init__(self, parent=None):

wx.Frame.__init__(self, parent, -1,

title='Disable / Enable all Widgets within a Sizer',size=(500,200))

self.Move((50,50))

panel = wx.Panel(self)

# layout (sizers, boxes,...):

top_sizer = wx.BoxSizer(wx.VERTICAL)

widget_box = wx.StaticBox(panel, id=-1,

label='Widgets, which are controlled')

widget_box.SetBackgroundColour("yellow")

control_box = wx.StaticBox(panel, -1,

label='Widgets, which controll')

control_box.SetBackgroundColour("yellow")

self.widget_sizer = wx.StaticBoxSizer(widget_box, wx.HORIZONTAL)

control_sizer = wx.StaticBoxSizer(control_box, wx.HORIZONTAL)

# create the widgets:

widget_1 = wx.TextCtrl(panel, value='Text 1')

widget_2 = wx.RadioButton(panel, label='Radio 1')

widget_3 = wx.RadioButton(panel, label='Radio 2')

widget_4 = wx.Button(panel, label='Button 1')

widget_disable = wx.Button(panel, label='DISABLE')

self.widget_enable = wx.Button(panel, label='ENABLE', pos = (100,50))

# add the widgets to the layout:

self.widget_sizer.Add(widget_1)

self.widget_sizer.Add(widget_2)

self.widget_sizer.Add(widget_3)

self.widget_sizer.Add(widget_4)

control_sizer.Add(widget_disable)

control_sizer.Add(self.widget_enable)

# finalize the layout:

top_sizer.Add(sizer=self.widget_sizer, flag=wx.CENTER | wx.EXPAND)

top_sizer.AddSpacer(30)

top_sizer.Add(control_sizer, 0, wx.CENTER | wx.EXPAND)

panel.SetSizer(top_sizer)

panel.Fit()

# bindings:

widget_disable.Bind(wx.EVT_BUTTON, self.on_button_disable)

self.widget_enable.Bind(wx.EVT_BUTTON, self.on_button_enable)

def on_button_disable(self, evt):

children = self.widget_sizer.GetChildren()

for child in children:

print(child.GetWindow(),end='')

try:

child.GetWindow().Enable(False)

print(' DISABLED')

except:

print(' ERROR')

def on_button_enable(self, evt):

children = self.widget_sizer.GetChildren()

for child in children:

print(child.GetWindow(),end='')

try:

child.GetWindow().Enable(True)

print(' ENABLED')

except:

print(' ERROR')

if __name__ == "__main__":

app = wx.App()

view1 = MainWindow()

view1.Show()

app.MainLoop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值