slightlynybbled / tk_tools

Python tkinter tools, Python3.7+
MIT License
101 stars 25 forks source link

Row title #22

Closed maicol07 closed 3 years ago

maicol07 commented 6 years ago

Hi, is it possible to add text as first element in table? Thanks

slightlynybbled commented 6 years ago

I must confess that I don't know which widget you are referring to. I don't have a Table class!

Could you be more specific?

If you are referring to the LabelGrid, then this should do:

root = tk.Tk()
lg = tk_tools.LabelGrid(root, num_of_columns=3, headers=['h1', 'h2', 'h3'])
lg.grid()

lg.add_row([1, 2, 3])
lg.add_row([5, 6, 7])

root.mainloop()

This will print headers h1, h2, and h3 with data.

maicol07 commented 6 years ago

No, I mean in Buttongrid add a row title (a label for row) at the start like column headers.

slightlynybbled commented 6 years ago

I can do that. Thanks!

slightlynybbled commented 6 years ago

buttongrid image

After having a look, the ButtonGrid already accomplishes this task!

check it out in the documentation!

maicol07 commented 6 years ago

@slightlynybbled but that are headers for columns not rows...

slightlynybbled commented 6 years ago

I don't know why I kept reading 'row' as 'column', but I did. Still looking at this!

j

slightlynybbled commented 6 years ago

I'm not sure how to maintain the API well. For instance, what happens at initialization? What happens when a row is added but no corresponding label is attached?

button_grid = tk_tools.ButtonGrid(
    root, 
    columns=3,
    headers=['Column0', 'Column1', 'Column2'],
    row_labels=['row 0', 'row 1'])

button_grid.add_row(['a', 'b', 'c'])  # row labeled with 'row 0'
button_grid.add_row(['d', 'e', 'f'])  # row labeled with 'row 1'
button_grid.add_row(['g', 'h', 'i'])  # what happens when this row is added without a label?

button_grid.grid(row=0, column=0)
maicol07 commented 6 years ago

What about keep the current row if there isn't an assigned label?

slightlynybbled commented 6 years ago

I concede that there are multiple ways to procede... but the behavior of the API is not absolutely clear... What about using the ButtonGrid.remove_row() method? Does that remove the row label as well or just the data? Are the row labels always visible? If row labels are added, does that "lock" the rows in the same way that the columns are locked?

maicol07 commented 6 years ago
slightlynybbled commented 6 years ago

What do you mean by are the row labels always visible?

The column headers are always visible. Same thing. It seems to me that if a user makes row labels, then the table has now become static in size. The columns are fixed, thus, the rows should be as well for consistency... agree?

maicol07 commented 6 years ago

Yes!

slightlynybbled commented 6 years ago

K, that's good. I like consistency in APIs and this discussion has given me a direction to move into.