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

CustomTkinter添加图片显示灰色方块而非正常图像的问题

问题:按钮旁添加图标显示灰色方块(CustomTkinter环境)

我尝试在应用的按钮旁添加小图标,但导入并放置图像后仅显示灰色方块。所用图像为非透明JPG格式,也尝试过PNG格式,期望支持透明PNG。窗口包含侧边栏和主屏幕两个框架,使用CustomTkinter库,图像与py文件同目录。

相关代码如下:

home_button = customtkinter.CTkButton(left_frame, text="Home", width=195, height=40, 
                                  corner_radius=10,
                                  text_font=["", "16"],
                                  fg_color=["#ffffff", "#000000"],
                                  hover_color=["#f4f5fa", "#1d1e20"],
                                  command=home
                                  )
home_button.place(x=50, y=80)
home_button.text_label.grid(sticky="w")

home_ico = ImageTk.PhotoImage(Image.open("home_def.jpg"))
home_label = Label(image=home_ico)
home_label.place(x=20, y=80)

添加图像前后的GUI截图:
GUI添加图像前
GUI添加图像后

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 21:21:13