python - Flet layout issue - Stack Overflow

I would like to generate the following layout:Two columns, each one taking the full height of the page.

I would like to generate the following layout:

  1. Two columns, each one taking the full height of the page.
  2. Column 1 contains items as Row objects.
  3. Column 2 also contains items as Row objects, but each Row contains multiple Container objects, and each Row should have an independent scroll bar.

I managed to generate a basic layout that resembles what I want, but:

  1. Column 1 does not take the full height.
  2. In Column 2, there is a single scroll bar for all Row objects.

Below is the code to reproduce my current layout:

def main2(page: ft.Page):

    searchArea = ft.Row(scroll="always")

    def buildContainer(text):
        return ft.Container(
                content=ft.Text(value=text),
                alignment=ft.alignment.center,
                width=page.width * 0.4,
                bgcolor=ft.colors.BLUE,
                border_radius=ft.border_radius.all(5))

    searchColumn = ft.Column(
            [
                buildContainer("Column 1 item 1"),
                buildContainer("Column 1 item 2"),
            ]
        )

    searchArea.controls.append(searchColumn)  # searchArea.controls[0]

    searchArea.controls.append(
        ft.Column(
            [
                ft.Row([buildContainer("Column 2 Row 1 item 1"), buildContainer("Column 2 Row 1 item 2")]),  # First feed area
                ft.Row([buildContainer("Column 2 Row 2 item 1"), buildContainer("Column 2 Row 2 item 2")]),
            ]
        )
    )
    page.add(searchArea) 

ft.app(main2)

I would like to generate the following layout:

  1. Two columns, each one taking the full height of the page.
  2. Column 1 contains items as Row objects.
  3. Column 2 also contains items as Row objects, but each Row contains multiple Container objects, and each Row should have an independent scroll bar.

I managed to generate a basic layout that resembles what I want, but:

  1. Column 1 does not take the full height.
  2. In Column 2, there is a single scroll bar for all Row objects.

Below is the code to reproduce my current layout:

def main2(page: ft.Page):

    searchArea = ft.Row(scroll="always")

    def buildContainer(text):
        return ft.Container(
                content=ft.Text(value=text),
                alignment=ft.alignment.center,
                width=page.width * 0.4,
                bgcolor=ft.colors.BLUE,
                border_radius=ft.border_radius.all(5))

    searchColumn = ft.Column(
            [
                buildContainer("Column 1 item 1"),
                buildContainer("Column 1 item 2"),
            ]
        )

    searchArea.controls.append(searchColumn)  # searchArea.controls[0]

    searchArea.controls.append(
        ft.Column(
            [
                ft.Row([buildContainer("Column 2 Row 1 item 1"), buildContainer("Column 2 Row 1 item 2")]),  # First feed area
                ft.Row([buildContainer("Column 2 Row 2 item 1"), buildContainer("Column 2 Row 2 item 2")]),
            ]
        )
    )
    page.add(searchArea) 

ft.app(main2)
Share Improve this question edited Nov 25, 2024 at 7:45 mkrieger1 23.3k7 gold badges64 silver badges81 bronze badges asked Nov 20, 2024 at 11:23 SosaSosa 14110 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

edit 1. I miss understood you at first time, this codde should be that you want.

If you want to give some feature like scroll to some control you need to add it to direct to it. Also expand attribute is that what you want to use to fit free space.

I delete attribute scroll from main row and it directly to column that you want have scroll and add expand attribute to main row to fit whole page, same in second column to fit witdh of not used page.

import flet as ft

def main2(page: ft.Page):

    searchArea = ft.Row(expand=1,
            vertical_alignment=ft.CrossAxisAlignment.START)

    def buildContainer(text):
        return ft.Container(
                content=ft.Text(value=text),
                alignment=ft.alignment.center,
                width=page.width * 0.4,
                bgcolor=ft.colors.BLUE,
                border_radius=ft.border_radius.all(5))

    searchColumn = ft.Column(
            [
                buildContainer("Column 1 item 1"),
                buildContainer("Column 1 item 2"),
            ],
        alignment=ft.MainAxisAlignment.START
        )

    searchArea.controls.append(searchColumn)  # searchArea.controls[0]

    searchArea.controls.append(
        ft.Column(
            [
                ft.Row([buildContainer("Column 2 Row 1 item 1"), buildContainer("Column 2 Row 1 item 2")],
                            scroll=ft.ScrollMode.ALWAYS,
                            expand=1
                            ),  # First feed area
                ft.Row([buildContainer("Column 2 Row 2 item 1"), buildContainer("Column 2 Row 2 item 2")],
                       expand=1,
                       scroll=ft.ScrollMode.ALWAYS),
                ],
            expand=1,
            scroll=ft.ScrollMode.ALWAYS,
            alignment=ft.MainAxisAlignment.START
        )
    )
    page.add(searchArea)

ft.app(main2)

After edit 1:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742361704a4429518.html

相关推荐

  • python - Flet layout issue - Stack Overflow

    I would like to generate the following layout:Two columns, each one taking the full height of the page.

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信