Search code examples
pythonwxpython

wxPython slider: Some module attributes appear to be missing


When I run this wxPython code:

        self.pwm_duty_cycle_slider = wx.Slider(self.panel, id=wx.ID_ANY,
                                           value=60, minValue=5,
                                           maxValue=95,
                                           style=wx.SL_VALUES)

it compiles without error.

However, when I change

      style=wx.SL_VALUES

to

      style=wx.SL_VALUE_LABEL

I get this traceback:

Traceback (most recent call last):
      File "C:\Users\Daniel\GitHub\FiberDrill\fiberdrill\gui.py", line 112, in on_laseroption
        LaserOptionDialog(self)
      File "C:\Users\Daniel\Documents\GitHub\FiberDrill\fiberdrill\gui.py", line 246, in __init__
        style=wx.SL_VALUE_LABEL)
    AttributeError: 'module' object has no attribute 'SL_VALUE_LABEL'

I'm a little confused, because according to the wxPython documentation wx.SL_VALUE_LABEL should be a valid attribute.

For reference, I'm using Enthought Canopy Python 2.7.3 (64-bit) and wxPython 2.8.10.1


Solution

  • Looks like that attribute was added in 2.9. Looking at the old 2.8 documentation (fancy version here: http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.Slider.html) you'll see it's not in the list. The docs you link to are Phoenix docs, so that definitely means it exists in Phoenix. And I just tested with 2.9.3.1 (classic) and it's there as well. Looks like you'll need to upgrade.

    By the way, there is nothing wrong with the 2.9 series. In many ways, it's even more stable than 2.8 or so says the creator of wxPython. However, the Phoenix build isn't ready for production and is only beta quality. I would stick with classic if you upgrade.