2015-12-22 59 views
0

我正在嘗試使用remove_widget函數讓我的按鈕在點擊後消失。根據documentation我相信這是實現這一目標的正確方法。但是,當我試圖刪除按鈕,我得到一個崩潰。不知道這是否與引用類型的小部件或別的東西有關。Kivy [widget]沒有任何屬性[child_widget]

這裏是我的main.kv

<MainPanel>: 
orientation: 'vertical' 
spacing: 1 

AppActionBar: 
    size_hint: (1., 0.1) 

ScrollView: 
    id: scrollview_main 
    do_scroll_x: False 
    do_scroll_y: False if root.fullscreen else (content.height > root.height - dp(16)) 
    AnchorLayout: 
     id: anchorlayout_main 
     size_hint_y: None 
     height: root.height if root.fullscreen else max(root.height, content.height) 
     GridLayout: 
      id: content 
      cols: 1 
      spacing: '8dp' 
      padding: '8dp' 
      size_hint: (1, 1) if root.fullscreen else (.8, None) 
      height: self.height if root.fullscreen else self.minimum_height 
      Button: 
       id: button_open_process 
       size_hint_y: None 
       text: 'Open New Process' 
       height: '48dp' 
       width: '120dp' 
       on_release: 
        root.open_process() 
        root.remove_widget(root.button_attach_process) <-- offending line 
        #root.remove_widget(root.button_open_process) 
      Button: 
       id: button_attach_process 
       size_hint_y: None 
       text: 'Attach to Currently Running Process' 
       height: '48dp' 
       width: '120dp' 
       on_release: root.attach_process() 

並與ID button_open_process

AttributeError: 'MainPanel' object has no attribute 'button_attach_process' 

是什麼原因造成這個問題點擊按鈕時,我得到的錯誤?

回答

1

在kv中管理動態窗口小部件有點尷尬,但無論如何問題在於設置一個id並沒有設置根窗口部件的屬性 - 這就是爲什麼它不存在。你可以直接使用root.remove_widget(button_attach_process),或者使用root.remove_widget(root.ids.button_attach_process),它也可以在python文件中使用。

相關問題