【发布时间】:2020-01-22 02:05:54
【问题描述】:
我正在为玩家帐户列表创建一个搜索菜单。
数据库中的球员姓名应显示在ScrollView 中。
我尝试使用GridLayout 或ScrollView 来做到这一点,但我想将玩家的昵称放在他的照片旁边,所以我认为使用FLoatLayout 是实现这一目标的更好方法。
不过,我不能让FLoatLayout 可滚动。
此代码正在运行:
class TestApp(App):
def build(self):
root = BoxLayout(orientation='horizontal', pos=(200, 100))
left=ScrollView(size_hint=[None, None], size=(194, 334))
leftGrid = GridLayout(cols=1, size_hint_y=None,padding=20)
leftGrid.bind(minimum_height=leftGrid.setter('height'))
for x in range (34):
self.image = Image(
source='other_nick.gif', pos=(0, 0),height=30,size_hint_y=None,)
label = Label(
text='hello world', pos=(-15, 20), height=30,size_hint_y=None,)
leftGrid.add_widget(self.image)
leftGrid.add_widget(label)
left.add_widget(leftGrid)
root.add_widget(left)
return root
if __name__ == "__main__":
TestApp().run()
但不是我想要的,因为它将文本放在图像旁边,但 FloatLayout 不可滚动:
class TestApp(App):
def build(self):
root = BoxLayout(orientation='horizontal', pos=(200, 100))
left=ScrollView(size_hint=[None, None], size=(194, 334))
fl = FloatLayout(size_hint_y=None)
y = 50
for x in range (34):
self.image = Image(
source='other_nick.gif', pos(0,y),height=30,size_hint_y=None,)
label = Label(
text='hello world', pos=(-15, y), height=30,size_hint_y=None,)
fl.add_widget(self.image)
fl.add_widget(label)
y -= 30
left.add_widget(fl)
root.add_widget(left)
return root
if __name__ == "__main__":
TestApp().run()
【问题讨论】:
-
当您将代码作为打印屏幕提供时,我们无法帮助并尝试您的代码。而是在你的问题中过去。为此,您可以edit您自己的问题
-
我做到了。我希望你能帮助我
标签: python kivy scrollview