Python wx 模块,EVT_TOGGLEBUTTON 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用wx.EVT_TOGGLEBUTTON

项目:code    作者:ActiveState    | 项目源码 | 文件源码
def _assignEvents(self):
        eventManager.Register(self.onListen, wx.EVT_TOGGLEBUTTON, self.btnListen)
        eventManager.Register(self.onConnect, wx.EVT_TOGGLEBUTTON, self.btnConnect)
        eventManager.Register(lambda e: self.Close(), wx.EVT_BUTTON, self.btnClose)
        eventManager.Register(self.onSend, wx.EVT_BUTTON, self.btnSend)

    # Event handlers for gui framework
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def __init__(self, parent, iec_type, defaultValue=""):
        wx.TextEntryDialog.__init__(
            self, parent,
            message=_("Forcing Variable Value"),
            caption=_("Please enter value for a \"%s\" variable:") % iec_type,
            defaultValue=defaultValue,
            style=wx.OK | wx.CANCEL | wx.CENTRE, pos=wx.DefaultPosition)

        self.IEC_Type = iec_type

        self.Bind(wx.EVT_BUTTON, self.OnOK,
                  self.GetSizer().GetItem(2).GetSizer().GetItem(1).
                  GetSizer().GetAffirmativeButton())
        self.ValueTextCtrl = self.GetSizer().GetItem(1).GetWindow()
        if self.IEC_Type == "BOOL":
            self.ToggleButton = wx.ToggleButton(self, label=_("Toggle value"))
            value = GetTypeValue[self.IEC_Type](defaultValue)
            if value is not None:
                self.ToggleButton.SetValue(value)

            border = self.GetSizer().GetItem(1).GetBorder()
            self.GetSizer().Insert(before=2, item=self.ToggleButton,
                                   border=border,
                                   flag=wx.LEFT | wx.RIGHT | wx.EXPAND)
            self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleBoolValue, self.ToggleButton)

        self.Fit()
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.defaultColor = self.GetBackgroundColour()

        rows = [("Ford", "Taurus", "1996", "Blue"),
                ("Nissan", "370Z", "2010", "Green"),
                ("Porche", "911", "2009", "Red")
                ]
        self.list_ctrl = wx.ListCtrl(self, style=wx.LC_REPORT)

        self.list_ctrl.InsertColumn(0, "Make")
        self.list_ctrl.InsertColumn(1, "Model")
        self.list_ctrl.InsertColumn(2, "Year")
        self.list_ctrl.InsertColumn(3, "Color")

        index = 0
        for row in rows:
            self.list_ctrl.InsertStringItem(index, row[0])
            self.list_ctrl.SetStringItem(index, 1, row[1])
            self.list_ctrl.SetStringItem(index, 2, row[2])
            self.list_ctrl.SetStringItem(index, 3, row[3])
            if index % 2:
                self.list_ctrl.SetItemBackgroundColour(index, "white")
            else:
                self.list_ctrl.SetItemBackgroundColour(index, "yellow")
            index += 1

        btn = wx.ToggleButton(self, label="Toggle Dark")
        btn.Bind(wx.EVT_TOGGLEBUTTON, self.onToggleDark)
        normalBtn = wx.Button(self, label="Test")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
        sizer.Add(btn, 0, wx.ALL, 5)
        sizer.Add(normalBtn, 0, wx.ALL, 5)
        self.SetSizer(sizer)