Re: On/off button?
Andrea Gavana <[email protected]>
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <CAEf70byZfOgBH4t5AEqz8zd=bdiWwe40Oo14VD0JbEPZ6NjdNg@mail.gmail.com> |
Hi, On Sun, 19 Jul 2020 at 10.47, Matthias Brennwald <[email protected]> wrote: > > > On Sa, Jul 18, 2020 at 20:15, Tim Roberts <[email protected]> wrote: > > On Jul 18, 2020, at 1:22 PM, Matthias Brennwald <[email protected]> > wrote: > > > Is there a way to make an "On/Off" button in wxPython like this: > > https://python-gtk-3-tutorial.readthedocs.io/en/latest/_images/switch_example.png > > > The easy way is to grab screen shots and use a wx.BitmapButton. That > doesn’t scale well, but it’s simple. > > > I don't want to use a "DIY bitmap" solution, because that will not look > right on most desktop environments. I guess what I really meant to ask was > if there is a solution that does what I want, and which looks right on all > desktop environments by using the standard "on/off" switch of this DE. If > yes: how? > Since there is nothing built-in as far as I can tell, I believe you have 3 alternatives (in increasing order of difficulty): 1. Use a wx.ToggleButton or one of the toggle buttons from wx.lib.buttons. The appearance is not the same as your switch control but it’s easy to implement, it occupies less space in the GUI and in my opinion it has a superior usability than the switch control. 2. Use a wx.Button and a wx.ToggleButton in a sizer to simulate the position of the switch handle and its status. Ugly, but it may work. 3. Create your own custom, owner-drawn control. Many of the widgets in wx.lib can provide you with a wealth of examples on how to do it (and see also https://wiki.wxpython.org/CreatingCustomControls). It doesn’t look so difficult for your switch control to do that, but of course if you care about native appearance on all platforms (whatever “native” means for a switch control) then you will have to take care of platform differences in color, font, size, etc... in the code. Andrea. -- > 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/4EKPDQ.8EPY5JMC2UEP2%40gmail.com > <https://groups.google.com/d/msgid/wxpython-users/4EKPDQ.8EPY5JMC2UEP2%40gmail.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/CAEf70byZfOgBH4t5AEqz8zd%3DbdiWwe40Oo14VD0JbEPZ6NjdNg%40mail.gmail.com.