2017-11-28 12 views
-3

私は、名前がAccountPopup(Popup)であるクラスを持っています:
私はaccountPopupクラスの変数state_id_textを定義します。私はself.state_id_text.textの値を.kv file.howから取得していますこの関数の値python - 自己を別の関数に渡す

def populate_tree_view_account_city(tree_view, parent, node): 

と印刷します。

class TreeviewCityAccount(Popup): 
    treeviewAccountCity = ObjectProperty(None) 
    tv = ObjectProperty(None) 
    h = NumericProperty(0) 
    #ti = ObjectProperty() 
    popup = ObjectProperty() 

    def __init__(self, **kwargs): 
     super(TreeviewCityAccount, self).__init__(**kwargs) 
     self.tv = TreeView(root_options=dict(text=""), 
         hide_root=False, 
         indent_level=4) 
     for branch in treeAccountState: 
      populate_tree_view_account_city(self.tv, None, branch) 
     #self.remove_widgets() 
     self.treeviewAccountCity.add_widget(self.tv) 
     Clock.schedule_once(self.update, 1) 

    def remove_widgets(self): 
     for child in [child for child in self.treeviewAccountCity.children]: 
      self.treeviewAccountCity.remove_widget(child) 

    def update(self, *args): 
     self.h = len([child for child in self.tv.children]) * 24 

    def filter(self, f): 
     self.treeviewAccountCity.clear_widgets() 
     self.tv = TreeView(root_options=dict(text=""), 
          hide_root=False, 
          indent_level=4) 
     new_tree = [] 
     for n in treeAccountCity: 
      if f.lower() in n['node_id'].lower(): 
       new_tree.append(n) 
     for branch in new_tree: 
      populate_tree_view_account_city(self.tv, None, branch) 

     self.treeviewAccountCity.add_widget(self.tv) 



def populate_tree_view_account_city(tree_view, parent, node): 
    #print(state_id_text.text) 
    if parent is None: 
     tree_node = tree_view.add_node(TreeViewLabelAccountCity(text=node['node_id'], 
                is_open=True)) 
    else: 
     tree_node = tree_view.add_node(TreeViewLabelAccountCity(text=node['node_id'], 
                is_open=True), parent) 

    for child_node in node['children']: 
     populate_tree_view_account_city(tree_view, tree_node, child_node) 

cur.execute("SELECT stateId FROM m_state WHERE stateName=?", (state_id_text.text,)) 
rows = cur.fetchall() 

treeAccountState = [] 

for r in rows: 
    treeAccountState.append({'node_id': r[1], 'children': []}) 

class AccountPopup(Popup): 
    state_id_text = ObjectProperty(None) 
    def display_cities_treeview_account(self, instance): 
     print(self.state_id_text.text) 
     if len(instance.text) > 0: 
      if self.popupAccountCity is None: 
       self.popupAccountCity = TreeviewCityAccount() 
       self.popupAccountCity.popup_account_city = self 
       self.popupAccountCity.filter(instance.text) 

誰かが私を助けることができますか?

+1

さて、インスタンスを作成して、その属性を関数に渡す必要があります。私が誤解した場合、あなたが何を期待しているのか分かりません。 – scharette

+0

**あなたのクラス 'AccountPopup'の中で関数' populate_tree_view_account_city' **を呼び出すことの目標はありますか? – scharette

答えて

0

クラス 'AccountPopup inside the function populate_tree_view_account_city , pass an object of the class 'AccountPopupのデータメンバーstate_id_textにアクセスしてアクセスする場合は、その関数にアクセスします。新しいインスタンスが作成されるたびに、関数populate_tree_view_account_city内にクラスの新しいインスタンスを作成し、state_id_textを初期化する場合は、AccountPopup内で__init__メソッドを使用します。

関連する問題