2017-12-12 8 views
0

カスタムボタンの変更をトリガするボタンをこのコードで使用します。私のソリューションは、すべてのカスタムボタンが押されたときにのみ色を変更します。ボタンを変更する適切な方法は何ですか?kivyのカスタムウィジェットの設定を変更するにはどうすればよいですか?

パイソン

class B_SettingScreen(Screen): 
    def change_color(self): 
     Factory.MainButton.background_normal = "z_MainButtonColorRed.jpg" 

kivyは

<[email protected]>: 
    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

だけでアプリのクラスでそれを変更する、(私は尋ねた別の質問で@ EL3PHANTENのおかげで)解決策を見つけました!

PY

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() 
関連する問題