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

使用CustomTkinter无法修改窗口及框架背景颜色求助

CustomTkinter 背景色问题解决方案

问题1:主窗口背景色无法修改

CustomTkinter的主窗口(CTk实例)不支持原生Tk的background参数,需使用fg_color来设置背景色。修改代码为:

# 方式1:创建窗口时直接指定
self.janela = ctk.CTk(fg_color='#446C65')

# 方式2:后续通过configure修改
self.janela.configure(fg_color='#446C65')

原生Tk的background参数对CustomTkinter的自定义窗口无效,因为它的渲染逻辑是重新实现的。

问题2:CTkFrame 添加bg参数报错

CTkFrame没有bg这个参数,CustomTkinter组件统一使用fg_color设置背景色(若需透明背景可设为"transparent")。正确写法示例:

my_frame = ctk.CTkFrame(self.janela, fg_color='#446C65')

使用未定义的bg参数会触发参数错误,移除后程序即可正常运行。

内容的提问来源于stack exchange,提问作者Caíque Rodrigues

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 11:29:50