[英]Resizing in Kivy makes blank space between widgets
I've created a basic GUI, to test scrollview and get a platform to build on further. 我已经创建了一个基本的GUI,以测试scrollview并获得进一步构建平台。 When resizing my window, there comes black space above my widgets, and there is also a lot of black space between them.
调整窗口大小时,小部件上方有黑色空间,它们之间也有很多黑色空间。
I've tried with "anchor" and "pos" but can't get the widgets to stay in the top of the window. 我已经尝试过使用“ anchor”和“ pos”,但是无法使小部件停留在窗口顶部。
class GUI(App):
def build(self):
root = FloatLayout(size_hint=(1, None), size=(Window.width, Window.height))
sidepanel = BoxLayout(orientation="vertical", size_hint=(None, 1), pos_hint={"x": 0.0, "y": 0.0})
scroll = ScrollView(pos_hint={"x": 0.2, "y": 0.0})
layout = BoxLayout(orientation="vertical", spacing=10, size_hint_y=None)
layout.bind(minimum_height=layout.setter('height'))
for i in range(50):
btn = Button(text=str(i), size_hint_y=None, height=30)
layout.add_widget(btn)
sidepanel.add_widget(Button(text="Import Photos", size_hint=(1,0.2)))
sidepanel.add_widget(Button(text="Create Report", size_hint=(1,0.2)))
sidepanel.add_widget(Button(text="Save?", size_hint=(1,0.2)))
sidepanel.add_widget(Button(text="Button 4", size_hint=(1,0.2)))
scroll.add_widget(layout)
root.add_widget(sidepanel)
root.add_widget(scroll)
return root
I would expect the sidepanel to stay the same size, and the scrollview containing "layout" to resize with the window. 我希望侧面板保持相同的大小,而包含“布局”的滚动视图将随窗口调整大小。 And all widgets should stay in the top.
并且所有小部件都应位于顶部。
Standard window 标准窗
Resized window 调整大小的窗口
Your issue is stemming from your size specifications in your 'root' floatlayout. 您的问题源于“根”浮动布局中的尺寸规格。 Try using:
尝试使用:
root = FloatLayout()
where you don't specify any size instructions. 您未指定任何尺寸说明的地方。 It will know how to resize itself properly automatically with the window.
它会知道如何使用窗口自动调整自身大小。 Generally you want to avoid using both
size_hint
and size
together on the same widget. 通常,您要避免在同一小部件上同时使用
size_hint
和size
。 Same goes for pos_hint
and pos
. pos_hint
和pos
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.