2017-12-02 32 views
0

アカウント(root.display_account())をクリックしてからdisplay_account()を呼び出し、そのRVACCOUNT()関数呼び出しの後に+ Add Accountをクリックするとデフ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) 

ルートとしてのアクセスよりも、それPYファイルや缶でStringPropertyそれを作る、どこにでもself.state_textとしてそれを参照する必要がありますが、あなたの場合は<TreeviewCityAccount>:別名最も左側のウィジェットを指します。

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

代わりにあなたはKVファイル内のIDと連携することができますを参照してください。