Kivy rule inherence with add_widget()

后端 未结 1 1968
不思量自难忘°
不思量自难忘° 2021-01-27 11:36

Follow up question: Kivy outside rule inherence

main.py

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.stacklayout import Stac         


        
相关标签:
1条回答
  • 2021-01-27 12:07

    Widget.ids only contain ids of its children (http://kivy.org/docs/api-kivy.uix.widget.html#kivy.uix.widget.Widget.ids. Id of the widget itself it's not needed because you can just pass it directly - in your case using self, since you're passing a reference to a widget from inside of a method:

    class Important(StackLayout):
        def NoInspiration(self, smile):
            print("Received: {}".format(smile))
    
        def AddFancy(self):
            print(self.ids) # only returns {'boxy': <weakproxy at 0000000002D119A8 to BoxLayout at 0000000002D026A8>}
            self.ids.boxy.add_widget(FancyButton(text='f', imp = self)) # no need to use a factory
    
    0 讨论(0)
提交回复
热议问题