Eto.Forms - Table Layout - Python 3

Hi All,

Upgrading some Eto.Forms from IronPython to Python3 - noticing a few changes which are easy to resolve - but stumped when needing to add rows to a table. Adding self. seems to solve a lot of
problems, but it doesn’t resolve when adding a row.

The self.table00.Rows.Add(label00a) will respond with an error regardless of having self. or not. Has method of adding table rows changed between the two versions of Python?

Error:
AttributeError: ‘0, Culture=neutral, PublicKeyToken=7cec85d7bea77’ object has no attribute ‘table00’

TableLayoutTrimmed.py (4.1 KB)

Thanks!

On line 25 you call self.CreateTable00() which moves execution to line 39 in the function CreateTable00. Then before creating the table00 object, you already try to use it on line 47, so the attribute table00 is not yet created on the self object, hence the error message.

I suggest you add this on line 46:

46: self.table00 = Eto.Forms.TableLayout() # create the table
47: self.table00.Rows.Add(label00a)

Thanks Menno, adding that solves this problem, and introduces a new one with the collections

def CreateTable00(self): # Text
    grid = forms.TableLayout()
    grid_cell = forms.TableCell(grid,True)
    grid_row = forms.TableRow(grid_cell)
    grid_row.ScaleHeight = True

    label00a = forms.Label()
    label00a.Text = 'EnterText:'

    self.table00 = forms.TableLayout() # create the table
    self.table00.Rows.Add(label00a)

Which is gets stuck on the last line with an error

TypeError: No method matches given arguments for Collection`1.Add: (<class ‘Eto.Forms.Label’>)

Any thoughts?

There is a lot of documentation for Eto on its Github pages.

To get started, see Home · picoe/Eto Wiki · GitHub
For TableLayout, see TableLayout · picoe/Eto Wiki · GitHub

As for your question, working with a TableLayout you need to create objects of type TableRow which can contain items of type TableCell. In the cells you can store UI elements. Your code would then become something like this:

cell = TableCell(label00)
row = TableRow(cell)
self.table00.Rows.Add(row)