2017-07-20 49 views
0

我試圖改變不同方法中按鈕的屬性。這是我目前正在使用:Kivy Python - 影響不同函數中的按鈕

def _finish_init(self, dt): 
    self.ids.grid_1.cols = 5 

    def callfun(self, *args): 
     self.ChangePic() 

    # Creating a variable to use to determine if the buttons should be editable 
    binded = 0 

    # Loop to make 15 different buttons on screen 
    for x in range(15): 
     self.buttons.append(Button()) 
     self.ids.grid_1.add_widget(self.buttons[x]) 
     self.buttons[x].background_normal = 'YOUTUBE.png' 
     self.buttons[x].background_down = 'opacity.png' 
     self.buttons[x].bind(on_release=partial(self.HoldButtonNum, x)) 


     # Make the button switch screens to input from calling the function above 
     if edit_mode is True: 
      self.buttons[x].bind(on_release=partial(self.SwitchScreenInput, x)) 

def ChangePic(self, *args): 
     _finish_init().buttons[1].background_normal = 'folder.png' 

當ChangePic叫我的錯誤:

NameError: name '_finish_init' is not defined

有什麼建議?

回答

0

它看起來像兩者的功能是一類的成員,則需要使用

self._finish_init()... 
+0

當使用self._finish_init(DT = 1).buttons [1] .background_normal = 'folder.png' 我我得到:「AttributeError:'NoneType'對象沒有屬性'按鈕'」 – John

+0

'_finish_init()'函數返回'None'。看看這個函數,我沒有看到任何返回語句。 – pypypy