kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Grid widget __getitem__() returns iterator.
rodzic
310957e518
commit
d6cc79e714
|
@ -1127,7 +1127,7 @@ Constructor args:
|
|||
in the `Label` as defined by `lwidth`.
|
||||
|
||||
Method:
|
||||
* `__getitem__` Return a list containing one or more `Label` instances.
|
||||
* `__getitem__` Returns an iterator enabling `Label` instances to be accessed.
|
||||
* `__setitem__` Assign a value to one or more labels. If multiple labels are
|
||||
specified and a single text value is passed, all labels will receive that
|
||||
value. If an iterator is passed, consecutive labels will receive values from
|
||||
|
@ -1156,7 +1156,11 @@ grid[1:3, 1:3] = (str(n) for n in range(2)) # Produces
|
|||
# 0 1
|
||||
# 1 1
|
||||
```
|
||||
|
||||
Read access:
|
||||
```python
|
||||
for label in grid[2, 0:]:
|
||||
v = label.value() # Access text of each label in row 2
|
||||
```
|
||||
Example uses:
|
||||
```python
|
||||
colwidth = (20, 30) # Col 0 width is 20, subsequent columns 30
|
||||
|
|
|
@ -46,12 +46,10 @@ class Grid(Widget):
|
|||
r += self.cheight
|
||||
c = col
|
||||
|
||||
def __getitem__(self, *args): # Return the Label instance
|
||||
def __getitem__(self, *args):
|
||||
indices = do_args(args, self.nrows, self.ncols)
|
||||
res = []
|
||||
for i in indices:
|
||||
res.append(self.cells[i])
|
||||
return res
|
||||
yield self.cells[i]
|
||||
|
||||
# allow grid[[r, c]] = "foo" or kwargs for Label:
|
||||
# grid[[r, c]] = {"text": str(n), "fgcolor" : RED}
|
||||
|
|
Ładowanie…
Reference in New Issue