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

Kivy圆角按钮文本被画布遮挡问题求助

Fix for Kivy Rounded Button Text Being Hidden

The problem arises because you're using the same color (self.color) for both the rounded rectangle background and the button text, making the text invisible. You already have the correct drawing order with canvas.before (which renders the background behind the text), so separating the background and text colors will fix the issue.

Here's the corrected code:

First, update the kv rule to use a dedicated background color property:

roundbutton = """
<RoundButton@Button>:
    background_color: (0, 0, 0, 0)
    background_normal: ''
    # Custom property for button background color
    btn_bg_color: (0.2, 0.15, 0.1, 1)  # Dark brown shade matching your expected effect
    canvas.before:
        Color:
            rgba: self.btn_bg_color
        RoundedRectangle:
            pos: self.pos
            size: self.size
            radius: [(20, 20)] * 4  # Shorter syntax for uniform corner radius
"""

Then, set distinct text and background colors when creating your button:

login_button = ScrButton(
    self, 
    direction='left', 
    goal='dashboard', 
    text='[b]LOGIN[/b]', 
    markup=True, 
    color=(237/255, 221/255, 182/255, 1),  # Light beige text color
    btn_bg_color=(0.2, 0.15, 0.1, 1),  # Dark button background
    size_hint=(.8, .07), 
    pos_hint={'center_x':.5, 'center_y':.3}
)

Key Changes:

  • btn_bg_color is a custom property that controls the rounded rectangle's fill color, separate from the text color (color).
  • canvas.before ensures the background is drawn behind the button text, so the text stays visible on top.
  • Adjust btn_bg_color to fine-tune the dark button shade to match your expected result.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 22:13:20