Python 如何在KivyMD中更改MDFloatingActionButtonSpeedDial中的定位值?

Python 如何在KivyMD中更改MDFloatingActionButtonSpeedDial中的定位值?,python,button,kivy-language,Python,Button,Kivy Language,我一直在与kivymd合作开发一个移动应用程序。但是我对MDFloatingActionButtonSpeedDial有一个问题。我想为一些按钮将MDFloatingActionButtonSpeedDial中的锚定值设置为“left”,为一些按钮设置为“right”。因此,我修改了模块“kivymd.uix.button”中的MDFloatingActionButtonSpeedDial类,并在“锚定”中添加了更多选项,该选项采用OptionProperty。除此之外,我还添加了应用更改所需的

我一直在与kivymd合作开发一个移动应用程序。但是我对MDFloatingActionButtonSpeedDial有一个问题。我想为一些按钮将MDFloatingActionButtonSpeedDial中的锚定值设置为“left”,为一些按钮设置为“right”。因此,我修改了模块“kivymd.uix.button”中的MDFloatingActionButtonSpeedDial类,并在“锚定”中添加了更多选项,该选项采用OptionProperty。除此之外,我还添加了应用更改所需的方法。acnhor的变化如下:-

anchor = OptionProperty('right',option=["right","left"])
方法的变化是:-

def set_pos_labels(self, widget):
    """Sets the position of the floating labels."""

    if self.anchor == "right":
        widget.x = Window.width - widget.width - dp(86)
    
    elif self.anchor == "left":
        widget.x = widget.width + dp(86)
    

def set_pos_root_button(self, instance):
    """Sets the position of the root button."""

    if self.anchor == "right":
        instance.y = dp(20)
        instance.x = Window.width - (dp(56) + dp(20))
        
    elif self.anchor == "left":
        instance.y = dp(20)
        instance.x = (dp(56) + dp(20))

def set_pos_bottom_buttons(self, instance):
    """Sets the position of the bottom buttons in a stack."""

    if self.anchor == "right":
        if self.state != "open":
            instance.y = instance.height / 2
        instance.x = Window.width - (instance.height + instance.width / 2)
        
    elif self.anchor == "left":
        if self.state != "open":
            instance.y = instance.height / 2
        instance.x = (instance.height + instance.width / 2)
我添加了左锚属性,因为默认情况下存在右锚

我编写的生成器字符串如下所示:-

MDFloatingActionButtonSpeedDial:
     data : app.data_download
     rotation_root_button : True
     id : download_button
     icon: 'download'
     anchor: 'left'
                    
                    
MDFloatingActionButtonSpeedDial:
      data : app.data_return
      rotation_root_button: True
      icon : 'arrow-left'
      anchor: 'right'
现在,每当我尝试将锚点属性设置为“左”,而不是构建器字符串文件中的默认选项(右),程序都会返回一个错误。我想告知,如果我将锚点的默认值设置为左,那么我会得到将锚点设置为右的错误,当我将锚点的默认值设置为右时,那么我会得到将锚点设置为左的错误。我得到的错误是:-

 Traceback (most recent call last):
 File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 700, in _apply_rule
 setattr(widget_set, key, value)
 File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
 File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__
 File "kivy\properties.pyx", line 541, in kivy.properties.Property.set
 File "kivy\properties.pyx", line 532, in kivy.properties.Property.set
 File "kivy\properties.pyx", line 1252, in kivy.properties.OptionProperty.check
 ValueError: MDFloatingActionButtonSpeedDial.anchor is set to an invalid option 'left'. Must be one 
 of: []

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "onlinecv2.py", line 500, in <module>
 ScanIt().run()
 File "C:\Users\user\Anaconda3\lib\site-packages\kivy\app.py", line 829, in run
 root = self.build()
 File "onlinecv2.py", line 435, in build
 camerascreen    = Builder.load_string(screen_helper)
 File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 405, in load_string
 rule_children=rule_children)
 File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 707, in _apply_rule
 e), cause=tb)
 kivy.lang.builder.BuilderException: Parser: File "<inline>", line 154:
 ...
     152:                        id : download_button
     153:                        icon: 'download'
 >>  154:                        anchor: 'left'
     155:
     156:
 ...
 ValueError: MDFloatingActionButtonSpeedDial.anchor is set to an invalid option 'left'. Must be one 
 of: []
 File "C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py", line 700, in _apply_rule
 setattr(widget_set, key, value)
 File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
 File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__
 File "kivy\properties.pyx", line 541, in kivy.properties.Property.set
 File "kivy\properties.pyx", line 532, in kivy.properties.Property.set
 File "kivy\properties.pyx", line 1252, in kivy.properties.OptionProperty.check
回溯(最近一次呼叫最后一次):
文件“C:\Users\user\Anaconda3\lib\site packages\kivy\lang\builder.py”,第700行,在应用规则中
setattr(小部件集合、键、值)
文件“kivy\weakproxy.pyx”,第35行,位于kivy.weakproxy.weakproxy.\uu setattr__
文件“kivy\properties.pyx”,第497行,在kivy.properties.Property.\uu集合中__
文件“kivy\properties.pyx”,第541行,在kivy.properties.Property.set中
文件“kivy\properties.pyx”,第532行,位于kivy.properties.Property.set中
文件“kivy\properties.pyx”,第1252行,位于kivy.properties.OptionProperty.check中
ValueError:MDFloatingActionButtonSpeedDial.anchor设置为无效选项“left”。一定是一个
共:[]
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“onlinecv2.py”,第500行,在
ScanIt().run()
文件“C:\Users\user\Anaconda3\lib\site packages\kivy\app.py”,第829行,正在运行
root=self.build()
文件“onlinecv2.py”,第435行,内部版本
camerascreen=Builder.load\u字符串(屏幕\u辅助对象)
文件“C:\Users\user\Anaconda3\lib\site packages\kivy\lang\builder.py”,第405行,加载字符串
规则\u子项=规则\u子项)
文件“C:\Users\user\Anaconda3\lib\site packages\kivy\lang\builder.py”,第707行,在应用规则中
e) ,原因=tb)
kivy.lang.builder.BuilderException:解析器:文件“”,第154行:
...
152:id:下载按钮
153:图标:“下载”
>>154:主播:“左”
155:
156:
...
ValueError:MDFloatingActionButtonSpeedDial.anchor设置为无效选项“left”。一定是一个
共:[]
文件“C:\Users\user\Anaconda3\lib\site packages\kivy\lang\builder.py”,第700行,在应用规则中
setattr(小部件集合、键、值)
文件“kivy\weakproxy.pyx”,第35行,位于kivy.weakproxy.weakproxy.\uu setattr__
文件“kivy\properties.pyx”,第497行,在kivy.properties.Property.\uu集合中__
文件“kivy\properties.pyx”,第541行,在kivy.properties.Property.set中
文件“kivy\properties.pyx”,第532行,位于kivy.properties.Property.set中
文件“kivy\properties.pyx”,第1252行,位于kivy.properties.OptionProperty.check中
当我在kivy文件中没有设置任何锚定值时,我得到的输出(这是不需要的)如下所示:-

因此,如果您能为我提供解决此错误的解决方案,以便我可以同时使用锚点属性“left”和“right”,我将非常高兴