问题描述
我正在尝试使用Python中的wxSlider创建一个带有范围选择选项的滑块.它具有可选的range参数,但问题是:
I'm trying to create a slider with option for range selection using wxSlider in Python. It has an optional range parameter but the problem is:
SL_SELRANGE:允许用户在滑块上选择一个范围.仅限Windows.
SL_SELRANGE: Allows the user to select a range on the slider. Windows only.
我正在使用Linux.我以为我可以继承wxSlider并使它在Linux上运行,或者自己创建一个自定义窗口小部件.问题是我不确定该如何选择.任何想法/指针/指向正确方向的想法都会受到赞赏.
And I'm using Linux.I thought I might subclass wxSlider and make it work on Linux, or create a custom widget on my own. The problem is I'm not sure how to go about either option.Any ideas/pointers/pointing me in the right direction would be appreciated.
我尝试过类似的事情:
range_slider = wx.Slider(parent, wx.ID_ANY, 0, 0, 100, style=wx.SL_HORIZONTAL | wx.SL_LABELS | wx.SL_SELRANGE)
但是"SL_SELRANGE"在Linux上什么也不做(应该提供两个句柄以选择范围).
but the "SL_SELRANGE" does nothing on Linux (should provide two handles, to select range).
推荐答案
您可以有两个滑块;一个会推高另一个,使它保持较低,而另一个会保持较高?
You could have two sliders; one that will push the other so it remains lower, and one will remain higher?
我知道这不是一回事,对不起,但这是一个选择.因此,当self.minSlider移动时,将wx.EVT_SCROLL与一个函数绑定,该函数将执行以下操作:
I know it isn't the same thing, sorry, but it is an option.So when ever self.minSlider is moved, you bind wx.EVT_SCROLL with a function that will do something like:
self.minSlider.Bind(wx.EVT_SCROLL, self.respondSliderChange())
def respondSliderChange(self):
if self.minSlider.GetValue() >= self.maxSlider.GetValue():
self.maxSlider.SetValue(self.minSlider.GetValue()+1)
,对于maxSlider,反之亦然.
and vice-versa for the maxSlider.
除此之外,您还可以在此处中创建一个自定义窗口小部件.
Besides that, you can look into creating a custom widget here.
这篇关于在Linux上使用范围创建wxSlider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!