Re: Looking for an "on/off" toggle control

Rolf <[email protected]> Tue, 12 Jan 2021 19:27:38 +0100
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
Simple demo of wx.ToggleButton


import wx

class Example(wx.Frame):
    def __init__(self, *args, **kw):
        super(Example, self).__init__(*args, **kw)
        pnl = wx.Panel(self)
        self.On = wx.ToggleButton(pnl, label='On', size=(40, -1),
pos=(20, 25))
        self.Off = wx.ToggleButton(pnl, label='', size=(40, -1),
pos=(60, 25))
        self.On.SetValue(True)

        self.On.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleOn)
        self.Off.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleOff)

        self.SetSize((250, 150))
        self.SetTitle('On/Off Toggle button')
        self.Show()

    def ToggleOn(self, event):
        self.On.SetLabel("On")
        self.On.SetValue(True)
        self.Off.SetValue(False)
        self.Off.SetLabel("")

    def ToggleOff(self, event):
        self.Off.SetLabel("Off")
        self.Off.SetValue(True)
        self.On.SetValue(False)
        self.On.SetLabel("")

if __name__ == "__main__":
    app = wx.App()
    ex = Example(None)
    app.MainLoop()

On 12/01/2021 14:38, [email protected] wrote:
> Dear All
>
> I am looking for a wxPython control that looks like an "on/off"
> switch. Something like this:
> https://developer.gnome.org/gtk3/stable/GtkSwitch.html
>
> I'd prefer a native implementation. I couldn't find anything in the
> docs, but maybe I am not looking at the right place. Any pointers?
>
> Thanks
> Matthias
> -- 
> You received this message because you are subscribed to the Google
> Groups "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wxpython-users/7fa13b5b-299c-4ee5-8f95-a3036806a107n%40googlegroups.com
> <https://groups.google.com/d/msgid/wxpython-users/7fa13b5b-299c-4ee5-8f95-a3036806a107n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/7d80bc27-1882-cc08-69e9-66cd340a2855%40gmail.com.