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

GUIZero使用多个Picture组件触发AttributeError崩溃问题求助

GUIZero使用多个Picture组件触发AttributeError崩溃问题求助

大家好,我最近在使用guizero开发图片 booth 程序时遇到了一个崩溃问题,折腾了好久都没解决,来求助社区的朋友们!

问题描述

当我在界面中添加多个Picture组件后,程序直接崩溃,触发了AttributeError错误。

复现步骤

我把问题简化成了一段测试代码,运行这段代码就能复现崩溃情况:

#GUI Classes
from guizero import App, PushButton, Picture, Text, Box, Window
import os

appDir = os.path.dirname(os.path.realpath(__file__))
app = App("Testing")

options = Box(app, layout="grid", width="fill")
Picture(options, appDir + '/images/icons/dark/100x100Filters-Icon@4x.png', width=100, height=100, grid=[0,0])
Picture(options, appDir + '/images/icons/dark/100x100PhotoFrames-Icon@4x.png', width=100, height=100, grid=[1,0])
Picture(options, appDir + '/images/icons/dark/100x100Stickers-Icon@4x.png', width=100, height=100, grid=[2,0])
Picture(options, appDir + '/images/icons/dark/100x100Timer-Icon@4x.png', width=100, height=100, grid=[3,0])
Picture(options, appDir + '/images/icons/dark/100x100Lights-Icon@4x.png', width=100, height=100, grid=[4,0])

filters = Box(app, layout="grid", width="fill").hide()

Picture(filters, appDir + '/images/icons/dark/100x100Smooth-Icon@4x.png', width=100, height=100, grid=[0,0])
Picture(filters, appDir + '/images/icons/dark/100x100SmoothM-con@4x.png', width=100, height=100, grid=[1,0])
Picture(filters, appDir + '/images/icons/dark/100x100Reset-Icon@4x.png', width=100, height=100, grid=[2,0])
Picture(filters, appDir + '/images/icons/dark/100x100Back-Icon@4x.png', width=100, height=100, grid=[3,0])

app.display()

预期行为

原本期望所有Picture组件都能正常加载显示,程序可以稳定运行。

报错截图

程序崩溃时的界面截图:
报错界面截图

我的运行环境

  • 操作系统:Windows 11 和 树莓派4的Raspbian系统,两个环境都出现了相同问题
  • guizero版本:Windows上为1.5.0,树莓派上为1.4.0

具体报错日志

运行程序后控制台输出的错误信息如下:

C:\Users\youca\Desktop\Photobooth App>python Test.py 
Traceback (most recent call last): 
  File "C:\Users\youca\Desktop\Photobooth App\Test.py", line 16, in <module> 
    Picture(filters, appDir + '/images/icons/dark/100x100Smooth-Icon@4x.png', width=100, height=100, grid=[0,0]) 
  File "C:\Users\youca\AppData\Local\Programs\Python\Python312\Lib\site-packages\guizero\Picture.py", line 55, in __init__ 
    tk = Label(master.tk) 
         ^^^^^^^^^ 
AttributeError: 'NoneType' object has no attribute 'tk'

有没有朋友遇到过类似的问题?或者能帮我分析下这个错误到底是哪里出了问题吗?

备注:内容来源于stack exchange,提问作者whatsmyname

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 13:28:06