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
相关产品推荐
相关产品推荐

