2017-12-02 7 views
0

계정 (root.display_account())을 클릭 한 다음 display_account()를 호출하면 해당 RVACCOUNT() 함수가 호출 된 후 + 계정 추가를 클릭하면 데프 add_account (자동) : 전화
python/kivy : .kv 파일의 액세스 속성 값

나는 속성 state_text를 정의하고 값 텍스트를 할당 클래스 AccountPopup이 '테스트'를 .kv 파일을 state_text '테스트'의 값을 얻을 on_text에 전달하는 방법을
: root.filter (self.text, state_text)와 def 필터 함수로 인쇄하십시오.

test.py

class AccountPopup(Popup): 
    state_text = ObjectProperty(None) 
    popupAccountCity = ObjectProperty(None) 


    def display_cities_treeview_account(self, instance): 
     if len(instance.text) > 0: 
      #if self.popupAccountCity is None: 
      self.popupAccountCity = TreeviewCityAccount(self.state_text.text) 
      self.popupAccountCity.filter(instance.text,self.state_text.text) 
     self.popupAccountCity.open() 


class TreeviewCityAccount(Popup): 
    state_text = ObjectProperty(None) 

    def __init__(self,state_text, **kwargs): 
     print(state_text) 

    def filter(self, f,state): 
     print(state) 


class RVACCOUNT(BoxLayout): 
    def add_account(self): 
     self.mode = "Add" 
     popup = AccountPopup(self) 
     popup.open() 

class MainMenu(BoxLayout): 

    def display_account(self): 
     self.dropdown.dismiss() 
     self.remove_widgets() 
     self.rvaccount = RVACCOUNT() 
     self.content_area.add_widget(self.rvaccount) 


class FactApp(App): 
    title = "Test" 

    def build(self): 
     self.root = Builder.load_file('test.kv') 
     return MainMenu() 



if __name__ == '__main__': 
    FactApp().run() 

test.kv

<AccountPopup>: 
    state_text:state_text 

     TextInput: 
      id:state_text 
      text:'Testing' 

<TreeviewCityAccount>: 

    BoxLayout 
     orientation: "vertical" 

     TextInput: 
      id: treeview 
      size_hint_y: .1 
      on_text: root.filter(self.text,state_text) 

<RVACCOUNT>: 
    BoxLayout: 
     orientation: "vertical" 
     Button: 
      size_hint: .07, .03 
      text: "+Add Account" 
      on_press: root.add_account() 


<MainMenu>: 
    content_area: content_area 
    dropdown: dropdown 

    BoxLayout: 
     orientation: 'vertical' 
     #spacing : 10 

     BoxLayout: 
      canvas.before: 
       Rectangle: 
        pos: self.pos 
        size: self.size 

      MenuButton: 
        id: btn 
        text: 'Master' 
        size : (60,30) 
        on_release: dropdown.open(self) 

      CustDrop: 

       DropdownButton: 
        text: 'Account' 
        size_hint_y: None 
        height: '32dp' 
        on_release: root.display_account() 

누군가가 나를 도울 수 있습니까?

+0

어디서 AccountPopup을여시겠습니까? – EL3PHANTEN

답변

0

당신은 또한 KV에서

on_text: root.filter(self.text,root.state_text) 

루트가 귀하의 경우 가장 왼쪽 위젯 일명 <TreeviewCityAccount>:을 의미로 접근보다 그에게 평 파일 수에 StringProperty을 사방 self.state_text로 참조해야합니다.

https://kivy.org/docs/api-kivy.lang.html enter image description here

는 다른 방법이 KV 파일의 ID로 사용할 수 있습니다 참조하십시오.