【问题标题】:Change the size of parent box layout kivy更改父框布局kivy的大小
【发布时间】:2020-08-28 21:10:16
【问题描述】:

我正在尝试使用 python 更改 kivy 中的四个父框布局大小。

代码-

class Run_app(App):

    def b1(self):
        
        self.b1 = BoxLayout(orientation="horizontal", spacing=10, size=(1, 0.15))
        #< ADDED Two to three box layouts to self.b1>
        return(self.b1)

    def b2(self):

        self.b2 = BoxLayout(orientation="horizontal", spacing=10, size=(1, 0.45))
        #< ADDED Two to three box layouts to self.b2>
        return(self.b2)

    def b3(self):

        self.b3 = BoxLayout(orientation="horizontal", spacing=10, size=(1, 0.20))
        #< ADDED Two to three box layouts to self.b3>
        return(self.b3)

    def b4(self):

        self.b4 = BoxLayout(orientation="horizontal", spacing=10, size=(1, 0.20))
        #< ADDED Two to three box layouts to self.b4>
        return(self.b4)

    def build(self):
        self.title = "GUI"
        self.root = BoxLayout(orientation="vertical", padding=15, spacing=15, )
        
        self.root.add_widget(self.b1())
        self.root.add_widget(self.b2())
        self.root.add_widget(self.b3())
        self.root.add_widget(self.b4())

        return(self.root)

我试图改变盒子的大小(b1,b2,b3,b4),但是大小没有改变,请你解释一下如何在kivy中改变父框布局的大小,

谢谢

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    如果您要设置size,则必须将size_hint 设置为None,否则您的size 设置将被忽略。例如:

        self.b1 = BoxLayout(orientation="horizontal", spacing=10, size=(1, 0.15), size_hint=(None, None))
    

    请注意,大小为 (1, 0.15) 的 BoxLayout 不会很有用。也许你的意思是:

        self.b1 = BoxLayout(orientation="horizontal", spacing=10, size_hint=(1, 0.15))
    

    (只需将size 替换为size_hint)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多