python - Kivy: programmatically create widget IDs -
i can't comment yet, forgive related post. i'm having same problem person: empty list of ids in kivy gridlayout
though i've found workaround answerer suggests, storing references gridded objects they're created, know if there way programmatically assign ids widgets can later accessed through parent's "ids" dictionary.
for example, in original question, code adds widgets this:
for in range(81): row = // 9 col = % 9 grid.add_widget(textinput(id = str(row) + "-" + str(col))) but id property used here apparently different id property if assign in kv file.
so expected output ids dict like:
{"1,1": *objectreference@blahblah*, "1,2": *objectreference@blahblah*, .....} but actual output is: {}
is there way make work expected? relatedly, worth find way/ better practice create own reference dictionary instead?
use built-in children list, automatically populated every added widget:
class mybutton(button): x = numericproperty(-1) y = numericproperty(-1) class mygrid(gridlayout): cols = numericproperty(1) def add_buttons(self): in xrange(10): button = mybutton(x=i, y=i) self.add_widget(button) def print_children(self): child in self.children: print 'button coords:', child.x, child.y
Comments
Post a Comment