2017-10-14 5 views
0

KV 파일에서 버튼의 배경색을 변경하고 싶지만 작동하지 않습니다. 버튼이 정의되어 있고 파이썬 파일에서 반복됩니다.파이썬에서 정의 된 KV 파일의 버튼에 액세스하기

def gotoPost(i, instance): 
    print("HAHAHAH") 
    Manager.current = 'ScreenTwo' 

class ScreenOne(Screen): 
    box = ObjectProperty(None) 

    def on_box(self, *args): 
     for i in range(5): 
      btn = Button(text=str(i)) 
      btn.bind(on_press=partial(gotoPost,i)) 
      self.box.add_widget(btn) 

Factory.register('ScreenOne', cls=ScreenOne) 

class ScreenTwo(Screen): 
    pass 

class Manager(ScreenManager): 

    screen_one = ObjectProperty(None) 
    screen_two = ObjectProperty(None) 

class MainApp(App): 
    def build(self): 
     return Manager() 
if __name__=="__main__": 
    MainApp().run() 

어떻게 KV 파일의 버튼에 액세스합니까?

답변

0
class ScreenOne(Screen): 
    box = ObjectProperty(None) 
    color = [1.0,1.0,1.0,1.0] 
    back_color = [0.0,0.0,0.0,1.0] 
    def on_box(self, *args): 
     for i in range(5): 
      btn = Button(text=str(i), color= self.color, background_color= self.back_color) 
      btn.bind(on_press=partial(gotoPost,i)) 
      self.box.add_widget(btn) 

누르면 버튼을 눌러 필요에 따라 색상을 변경할 수 있습니다. 예 : self.color 또는 self.back_color = (7,0,1,1) ... 빨간색이라고 생각합니다.

+0

질문은 "KV 파일의 버튼에 어떻게 액세스합니까?"입니다. 파이썬 스크립트에서는 그렇지 않습니다. – ikolim