KivyMD按钮边框颜色无法修改问题求助:使用line_color属性无效
I’ve run into this exact issue before! The problem here is two-fold: your buttons are still using the default KivyMD theme for their border color, and the default border width is set to 0 (so even if the color was correct, you wouldn’t see it). Here’s how to fix it:
Key Changes Needed:
- Add
theme_line_color: "Custom"to both buttons to override the default theme and activate your customline_colorsetting. - Set a
line_widthvalue greater than 0 (e.g.,line_width: 2) to make the border visible.
Modified Working Code:
from kivymd.app import MDApp from kivy.lang import Builder Root=""" #:import hex kivy.utils.get_color_from_hex BoxLayout: id:Layout_1 padding: 20 spacing: 20 MDRoundFlatButton: size_hint: None, None size: 220, 50 # Explicit size for better visibility text:"MDRoundFlatButton" theme_text_color: "Custom" text_color: 0, 0, 0, 1 # Black text for contrast with white background font_size:16 id:btn theme_line_color: "Custom" # Enable custom border color line_color: 1, 1, 0, 1 # Yellow border line_width: 2 # Set border thickness md_bg_color:1, 1, 1, 1 # White background MDRectangleFlatButton: text: "MDRECTANGLEFLATBUTTON" theme_text_color: "Custom" text_color: 1, 0, 0, 1 theme_line_color: "Custom" # Enable custom border color line_color: 1, 1, 0, 1 # Yellow border line_width: 2 # Set border thickness """ class Main(MDApp): def build(self): return Builder.load_string(Root) Main().run()
Explanation:
theme_line_color: "Custom"tells KivyMD to ignore the default theme’s border color and use your specifiedline_colorinstead.line_width: 2sets the thickness of the border—without this, the border has zero width and remains invisible, even if the color is correctly set.- I added padding/spacing to the layout and adjusted the text color to black to make the button content more readable against the white background and yellow border.
This should give you the yellow border you’re expecting on both buttons!
内容的提问来源于stack exchange,提问作者Ctrl7
相关产品推荐
相关产品推荐

