我有这个代码,我想要一个按钮来触发自定义按钮的更改。我的解决方案仅在按下时更改所有自定义按钮的颜色。改变按钮的正确方法是什么?
蟒
class B_SettingScreen(Screen):
def change_color(self):
Factory.MainButton.background_normal = "z_MainButtonColorRed.jpg"
kivy
<MainButton@Button>:
font_size: 18
markup: True
size_hint: 0.25,0.06
color: 0,0,0,1
background_normal: "z_MainButtonColor.jpg"
<B_SettingScreen>:
MainButton:
text: "[b][font=Arial]Change Color[/b][/font]"
pos_hint: {"center_x":0.25, "y":0.5}
on_release: root.change_color()
答案 0 :(得分:0)
找到解决方案(感谢@ EL3PHANTEN在我问的另一个问题中),只需用app类更改它!
吡啶
class Bobolo(App):
bg_but = StringProperty("z_MainButtonColor.jpg")
def build(self):
Window.clearcolor = 1,1,1,1
return A_ScreenManager()
def change_bg(self):
self.bg_but = "z_MainButtonColorRed.jpg"
KV
<MainButton>:
id: MainButton
font_size: 18
markup: True
size_hint: 0.25,0.06
color: 0,0,0,1
background_normal: app.bg_but
<B_SettingScreen>:
MainButton:
text: "[b][font=Arial]Change Color[/b][/font]"
pos_hint: {"center_x":0.25, "y":0.5}
on_release: app.change_bg()