Running the code below on Python 3.8.10 + wxPython 4.1.1 gtk3 (phoenix) wxWidgets 3.1.5 + Linux Mint 20.3, I don’t get the extra random tags shown in your example.
import wx
import wx.lib.agw.knobctrl as KC
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((200, 200))
self.panel = wx.Panel(self, wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
self.volume_ctrl = KC.KnobCtrl(self.panel, wx.ID_ANY, size=(100, 100))
sizer.Add(self.volume_ctrl, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
self.panel.SetSizer(sizer)
self.Layout()
# Override the default max value
self.volume_ctrl._maxvalue = 64
self.volume_ctrl.SetTags((0,8,16,24,32,40,48,56,64))
self.volume_ctrl.SetAngularRange(-45, 225)
self.volume_ctrl.SetLabel("Volume")
self.Bind(KC.EVT_KC_ANGLE_CHANGED, self.OnAngleChanged, self.volume_ctrl)
def OnAngleChanged(self, event):
print(event.GetValue())
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "KnobCtrl")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
For some reason, the SetTags() method only overrides the max value if it’s greater than the default value of 100. However, explicitly setting the control’s _maxvalue attr seems to work.
I have a couple of other issues with the KnobCtrl:
- Some of the tags are drawn inside the shaded square, while other extend outside it.
- When you rotate the knob, the size of the circular position indicator fluctuates randomly.
I think the SetLabel() method is inherited from wx.Window, but it has no visible effect on the KnobCtrl.