【问题标题】:KivyMD ProgressBar ThicknessKivyMD 进度条厚度
【发布时间】:2021-10-19 10:41:39
【问题描述】:

如何在 KivyMD 中调整 MDProgressBar 的粗细?我尝试了以下方法,但它不起作用

MDProgressBar:
    value: 50
    size_hint: 1, None
    height: 2

【问题讨论】:

    标签: python python-3.x kivy kivymd


    【解决方案1】:

    不,在我发布此答案时您无法更改它,您可以在源代码中看到 here 是恒定的,等于 '4sp' 所以不可能

    【讨论】:

      【解决方案2】:

      只是一个height = dp(48)的小例子

      from kivymd.app import MDApp 
      from kivy.uix.screenmanager import Screen, ScreenManager
      from kivy.lang import Builder
      KV = '''
      <home>:
          progression_value:25
          
          BoxLayout:
              orientation:'vertical'
              padding:dp(24),0,dp(24),0
              Widget:
              
              MDProgressBar:
                  value: root.progression_value
                  color: 0,0,0,0
                  size_hint_y:None
                  height:dp(48)                                   
                  canvas:
          
                      Color:
                          rgba:1,1,0,1
                      BorderImage:
                          border: (dp(48), dp(48), dp(48), dp(48))
                          pos: self.x, self.center_y - dp(24)
                          size: self.width, dp(48)
                      Color:
                          rgba:1,0,0,1                        
                      BorderImage:
                          border: [int(min(self.width * (self.value / float(self.max)) if self.max else 0, dp(48)))] * 4
                          pos: self.x, self.center_y -dp(24)
                          size: self.width * (self.value / float(self.max)) if self.max else 0, dp(48)
          
              Widget:            
      ''' 
      class home(Screen):
          pass
      
      class Test(MDApp): 
          def build(self): 
              Builder.load_string(KV)
              self.sm = ScreenManager()
              self.sm.add_widget(home(name="home"))
      
              return self.sm
          
      Test().run() 
      

      enter image description here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-17
        • 2018-07-12
        • 1970-01-01
        • 2014-01-13
        • 1970-01-01
        相关资源
        最近更新 更多