更改父框布局kivy的大小
Change the size of parent box layout kivy
我正在尝试使用 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中改变父盒子布局的大小,
谢谢
如果您正在设置 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
)。
我正在尝试使用 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中改变父盒子布局的大小,
谢谢
如果您正在设置 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
)。