如何解决Kivy:滑块;如何设置位置在声明中创建时的值或规范化值
在文档中,滑块位置属性的类型为 AliasProperty。 我无法弄清楚如何设置位置。 有人在那里看到过这项工作吗? 字符串、整数和任何我尝试过的东西都失败了。 是否有特殊格式来设置/引用滑块位置? 谢谢
类 MyContainer(GridLayout):
autopct
应用类
类 MySliders(App):
def __init__(self,**kwargs):
# super function can be used to gain access to inherited methods from a parent or sibling class that has been overwritten in a class object.
super(MyContainer,self).__init__(**kwargs)
# 4 columns in grid layout
self.cols = 4
# declaring the slider and adding some effects to it self.brightnessControl = Slider(min = 0,max = 100)
self.orientation = "lr-tb"
self.changed = False
self.brightnessControl = Slider(min = -255,max = 255,value_track = True,value_track_color =[1,1])
self.brightnessControl.id = 'brt slider'
self.add_widget(Label(text ='brightness'))
self.add_widget(self.brightnessControl)
self.add_widget(Label(text ='Adj Brightness'))
self.brightnessValue = Label(text = str(brightadj))
self.add_widget(self.brightnessValue)
# On the slider object Attach a callback for the attribute named value
self.brightnessControl.bind(value = self.on_value)
self.contrastControl = Slider(min = -255,1])
self.contrastControl.id = 'contr slider'
self.add_widget(Label(text ='contrast'))
self.add_widget(self.contrastControl)
self.add_widget(Label(text ='Adj Contrast'))
self.contrastValue = Label(text = str(conTradj))
self.add_widget(self.contrastValue)
# On the slider object Attach a callback for the attribute named value
self.contrastControl.bind(value = self.on_value)
self.thresholdControl = Slider(min = 10,max = 245,1])
self.thresholdControl.id = 'thresh slider'
self.add_widget(Label(text ='threshold'))
self.add_widget(self.thresholdControl)
self.add_widget(Label(text ='Adj Threshold'))
self.thresholdValue = Label(text = str(thresh))
self.add_widget(self.thresholdValue)
# On the slider object Attach a callback for the attribute named value
self.thresholdControl.bind(value = self.on_value)
# Adding functionality behind the slider i.e when pressed increase the value
def on_value(self,instance,value):
if instance.id == 'brt slider':
self.brightnessValue.text = "% d"% value
global brightadj
brightadj = value
if instance.id == 'contr slider':
self.contrastValue.text = "% d"% value
global conTradj
conTradj = value
if instance.id == 'thresh slider':
self.thresholdValue.text = "% d"% value
global thresh
thresh = value
MyContainer().changed = True
MySliders.my_value(instance,value)
解决方法
Slider 类中没有 position
,我假设您的意思是 value_pos
,它是根据值确定的,您真的需要独立于值更改 value_pos
吗?如果没有,只需设置适当的值,它就会设置适当的 value_pos
,如果您确实需要独立设置它,您可能希望构建自己的类 Slider,并为您的用例提供适当的行为,因为不是 Slider。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。