Kivy圆角按钮文本被画布遮挡问题求助
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_coloris a custom property that controls the rounded rectangle's fill color, separate from the text color (color).canvas.beforeensures the background is drawn behind the button text, so the text stays visible on top.- Adjust
btn_bg_colorto fine-tune the dark button shade to match your expected result.
内容的提问来源于stack exchange,提问作者Helena
相关产品推荐
相关产品推荐

