【发布时间】:2020-12-18 22:43:37
【问题描述】:
我有一个基于 Tech With Tim 的 Kivy 教程应用程序的 FloatLayout。 FloatLayout 允许在任何设备上调整窗口大小,因为此应用程序将在 Android 和 iOS 上使用。 我已经想出了如何将 gridlayout 和 scrollview 放置在 floatlayout 中并将其放置在我想要的位置,但我需要能够滚动浏览红色项目列表。 (见图)
现在,它响应滚动,但不会一直滚动到列表中并停止或完全停留。项目按钮列表也延伸到视图之外并且从不压缩。不过,不确定这是否可以解决。
代码:
class MainWindow(Screen):
def sendData(self, data):
pass
def logOut(self):
sm.current = "login"
def on_enter(self):
sundries = Sundry(join('Sundries.xlsx'))
supplies = sundries.get_supplies()
titleBtn = Button(text=supplies[0], size_hint=(0.4, 0.2), pos_hint={'x': 0,'y':0.8}, background_color=(0,0,255,1))
root = ScrollView(size_hint=(0.4,0.8))
layout = GridLayout(cols=1, spacing=1, size_hint=(0.8,0.7))
# Make sure the height is such that there is something to scroll.
for i in range(1, len(supplies), 1):
btn = Button(text=supplies[i], size_hint_y=None, height=40,background_color=(255,0,0,1))
layout.add_widget(btn)
root.add_widget(layout)
self.add_widget(root)
self.add_widget(titleBtn)
如果你能帮我解决这个问题,真的很感激你的时间:)
【问题讨论】:
标签: python python-3.x kivy