You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flet开发疑问:intro_card变量中的Container为何无法显示?

问题原因及解决方法:Flet子容器无法显示

你的代码中存在一个语法错误,导致组件无法正常渲染:

  • 设置page.window.resizable时,末尾多了一个逗号,使得赋值结果为元组(True,),但Flet的window.resizable属性要求接收布尔值(True/False)。这个错误会干扰Flet的窗口初始化逻辑,进而导致后续子容器无法正常显示。

修正后的代码

from flet import *

def main(page: Page):
    page.window.width = 411        
    page.window.height = 891      
    page.window.resizable = True  # 移除末尾多余的逗号
    page.bgcolor = 'blue'
    
    intro_card = Column(
        controls=[
            Container(
                width=100,
                height=200,
                bgcolor='green'
            )
        ]
    )
  
    main_content = Container(
        width=350,
        height=500,
        bgcolor='#d6ecf2',
        alignment='center',
        content=intro_card
    )                                       

    page.add(main_content)
    
    page.update()

app(target=main)

移除多余的逗号后,窗口的可调整大小属性被正确设置为布尔值,Flet页面初始化流程恢复正常,intro_card内的绿色Container就能正常显示在主容器的中心位置。

内容的提问来源于stack exchange,提问作者pavan sunder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 06:29:59