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

CTkScrollableFrame与pywinstyles.set_opacity不兼容导致按钮异常消失问题求助

CTkScrollableFrame与pywinstyles.set_opacity不兼容导致按钮异常消失问题求助

我最近在做CustomTkinter项目时碰到了一个棘手的问题:当使用pywinstyles.set_opacity给按钮设置透明效果时,如果按钮或它所在的Frame直接放在根窗口下,一切都正常,按钮背景能按照预期变成透明状态。

可一旦把这个Frame或者按钮放到CTkScrollableFrame里面,按钮就直接完全消失了,只有当鼠标悬停在它上面的时候才会显示出来。

以下是我用到的代码片段:

scrollable_frame = ctk.CTkScrollableFrame(root, fg_color="transparent")
scrollable_frame.pack(fill="both", expand=True)
scrollable_frame.grid_columnconfigure(0, weight=1)


frame = ctk.CTkFrame(scrollable_frame, width=CWidth, height=CHeight, corner_radius=20)
frame.grid_propagate(False)

button = ctk.CTkButton(frame, text="", fg_color="#00B06F", bg_color="#00B16F", hover_color="#009A5F", width=90, height=30, corner_radius=15)
button.grid(row=2, column=0, padx=5, pady=2, sticky="w")
pywinstyles.set_opacity(button, color="#00B16F")

我本来是想用这个方法实现按钮的圆角效果,试了别的办法都没成功,而且项目里必须用到可滚动框架。后来尝试用root.after延迟调用设置透明度的函数,虽然能暂时解决问题,但总不能让用户等1秒吧,这显然不是个靠谱的解决方案。有没有大佬能帮忙看看怎么解决这个问题呀?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 16:59:36