How to Position wxPython slider control

I'm not having any success at setting the horizontal position of
wxPythons slider controls.
In all my attempts setting the horizontal position has no effect on
the placement of the control.
Can any one tell me what I'm missing? Thanks

Here's what I've tried:

    import wx

    class SliderFrame(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, 'Slider Example',
size=(400, 600))
            panel = wx.Panel(self, -1)
            self.count = 0
            hslider1 = wx.Slider(panel, 100, 25, 1, 100, pos=(10, 10),
                    size=(250, -1),
                    style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS |
wx.SL_LABELS )
            hslider1.SetTickFreq(5, 1)

            hslider2 = wx.Slider(panel, 100, 25, 1, 100, pos=(100,
330),
                    size=(250, -1),
                    style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS |
wx.SL_LABELS )
            hslider2.SetTickFreq(5, 1)

            vslider1 = wx.Slider(panel, 100, 25, 1, 100, pos=(15, 70),
                    size=(-1, 250),
                    style=wx.SL_VERTICAL | wx.SL_AUTOTICKS |
wx.SL_LABELS )
            vslider1.SetTickFreq(20, 1)

    app = wx.PySimpleApp()
    frame = SliderFrame()
    frame.Show()
    app.MainLoop()

Try using Sizers. It is much more flexible and easier to maintain.

Gadget/Steve

···

On 26/02/2012 11:00 PM, DavidG wrote:

I'm not having any success at setting the horizontal position of
wxPythons slider controls.
In all my attempts setting the horizontal position has no effect on
the placement of the control.
Can any one tell me what I'm missing? Thanks

Here's what I've tried:

    import wx

    class SliderFrame(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, 'Slider Example',
size=(400, 600))
            panel = wx.Panel(self, -1)
            self.count = 0
            hslider1 = wx.Slider(panel, 100, 25, 1, 100, pos=(10, 10),
                    size=(250, -1),
                    style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS |
wx.SL_LABELS )
            hslider1.SetTickFreq(5, 1)

            hslider2 = wx.Slider(panel, 100, 25, 1, 100, pos=(100,
330),
                    size=(250, -1),
                    style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS |
wx.SL_LABELS )
            hslider2.SetTickFreq(5, 1)

            vslider1 = wx.Slider(panel, 100, 25, 1, 100, pos=(15, 70),
                    size=(-1, 250),
                    style=wx.SL_VERTICAL | wx.SL_AUTOTICKS |
wx.SL_LABELS )
            vslider1.SetTickFreq(20, 1)

    app = wx.PySimpleApp()
    frame = SliderFrame()
    frame.Show()
    app.MainLoop()

My plan was to place the panel in a sizer and add a plot canvas beside
the vertical slider so I need to be able to position the proper x-
coordinates of the horizontal sliders.
What good will sizers do if it won't properly place in the parent
panel?

···

On Feb 26, 10:06 pm, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

On 26/02/2012 11:00 PM, DavidG wrote:

> I'm not having any success at setting the horizontal position of
> wxPythons slider controls.
> In all my attempts setting the horizontal position has no effect on
> the placement of the control.
> Can any one tell me what I'm missing? Thanks

> Here's what I've tried:

> import wx

> class SliderFrame(wx.Frame):
> def __init__(self):
> wx.Frame.__init__(self, None, -1, 'Slider Example',
> size=(400, 600))
> panel = wx.Panel(self, -1)
> self.count = 0
> hslider1 = wx.Slider(panel, 100, 25, 1, 100, pos=(10, 10),
> size=(250, -1),
> style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS |
> wx.SL_LABELS )
> hslider1.SetTickFreq(5, 1)

> hslider2 = wx.Slider(panel, 100, 25, 1, 100, pos=(100,
> 330),
> size=(250, -1),
> style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS |
> wx.SL_LABELS )
> hslider2.SetTickFreq(5, 1)

> vslider1 = wx.Slider(panel, 100, 25, 1, 100, pos=(15, 70),
> size=(-1, 250),
> style=wx.SL_VERTICAL | wx.SL_AUTOTICKS |
> wx.SL_LABELS )
> vslider1.SetTickFreq(20, 1)

> app = wx.PySimpleApp()
> frame = SliderFrame()
> frame.Show()
> app.MainLoop()

Try using Sizers. It is much more flexible and easier to maintain.

Gadget/Steve

Platform and version? Your sample seems to be working correctly for me on Windows with 2.9.3.1.

···

On 2/26/12 3:00 PM, DavidG wrote:

I'm not having any success at setting the horizontal position of
wxPythons slider controls.
In all my attempts setting the horizontal position has no effect on
the placement of the control.
Can any one tell me what I'm missing? Thanks

--
Robin Dunn
Software Craftsman

The problem you are seeing is probably due to the panel still being very small at the time that the sliders are created and positioned. OTOH, sizers will normally redo the layout on every size event that the window they are assigned to receives, so you are not stuck with the initial layout.

···

On 2/27/12 1:46 AM, DavidG wrote:

My plan was to place the panel in a sizer and add a plot canvas beside
the vertical slider so I need to be able to position the proper x-
coordinates of the horizontal sliders.
What good will sizers do if it won't properly place in the parent
panel?

--
Robin Dunn
Software Craftsman

Thanks for your comment Robin. I'm using Mac OSX 10.6.8, Python 2.6.5
wxPython 2.9.2.4.
The Slider behaves as expected if I change the 2nd size parameter from
size=(250, -1) to size=(250, 100)
Is this a bug on the Mac OSX?

···

On Feb 27, 2:28 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 2/27/12 1:46 AM, DavidG wrote:

> My plan was to place the panel in a sizer and add a plot canvas beside
> the vertical slider so I need to be able to position the proper x-
> coordinates of the horizontal sliders.
> What good will sizers do if it won't properly place in the parent
> panel?

The problem you are seeing is probably due to the panel still being very
small at the time that the sliders are created and positioned. OTOH,
sizers will normally redo the layout on every size event that the window
they are assigned to receives, so you are not stuck with the initial layout.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Probably. Submit a ticket.

···

On 2/27/12 8:35 PM, DavidG wrote:

Thanks for your comment Robin. I'm using Mac OSX 10.6.8, Python 2.6.5
wxPython 2.9.2.4.
The Slider behaves as expected if I change the 2nd size parameter from
size=(250, -1) to size=(250, 100)
Is this a bug on the Mac OSX?

--
Robin Dunn
Software Craftsman

If it helps, I'm seeing the same problem and the same solution (don't
use -1 in the size tuple) with wxPython2.8 running python 2.7.1 on Mac
OS X Lion (10.7.3). I also noticed that I don't have the problem if
the slider is the only widget in the panel; it only refuses to set the
x position when there are other widgets present. I'm new to wxPython
and haven't yet tried sizers - I am working on that next.

Paul

···

On Feb 28, 12:42 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 2/27/12 8:35 PM, DavidG wrote:

> Thanks for your comment Robin. I'm using Mac OSX 10.6.8, Python 2.6.5
> wxPython 2.9.2.4.
> TheSliderbehaves as expected if I change the 2nd size parameter from
> size=(250, -1) to size=(250, 100)
> Is this a bug on the Mac OSX?

Probably. Submit a ticket.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org