I’m not having any luck at setting the horizontal position of wxPythons slider controls. In all my tests 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()
That’s odd. An obvious work around is to put the slider in a panel that you can position (below), or use sizers. Also, note that the error goes away if you use
It also works to use
SetDimensions, like this: