私はあなたが望むことをすると思う簡単なスクリプトを書きました:
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.slider_value = 1
self.slider = wx.Slider(self, value=1, minValue=0, maxValue=100, size=(250, -1),
style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
self.slider.SetTickFreq(5, 1)
self.slider.Bind(wx.EVT_SCROLL, self.onScroll)
self.toggle = wx.ToggleButton(self, label="Start")
self.toggle.Bind(wx.EVT_TOGGLEBUTTON, self.onToggle)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onUpdate, self.timer)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.slider, 0, wx.ALL, 5)
sizer.Add(self.toggle, 0, wx.ALL, 5)
self.SetSizer(sizer)
#----------------------------------------------------------------------
def onScroll(self, event):
"""
Fires when you manually scroll the slider
"""
value = self.slider.GetValue()
self.slider_value = value
#----------------------------------------------------------------------
def onToggle(self, event):
"""
Start / Stop the slider incrementing
"""
value = self.toggle.GetValue()
if value:
self.toggle.SetLabel("Pause")
self.timer.Start(1000)
else:
self.timer.Stop()
self.toggle.SetLabel("Start")
#----------------------------------------------------------------------
def onUpdate(self, event):
"""
Increment the slider
"""
self.slider_value += 1
self.slider.SetValue(self.slider_value)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Slider Test")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()