Search code examples
pythonwxpythonwxwidgets

Multiple headers for a table wx Python


Howdi folks, I have recently started dabbling in WX widgets using Python and would like to seek some direction on a task I want to achieve. The challenge here is to have a table with multiple headers i.e. headers spanning multi-lines with logical grouping. To show an example:

-----------------------------------------------------
|        header_main_1      |     header_main_2     |
-----------------------------------------------------
| sub_1       |  sub_2      |  sub_3     |   sub_4  |
-----------------------------------------------------
-----------------------------------------------------
| data1       |  data2      |  data3     |   data4  |
-----------------------------------------------------
| data5       |  data6      |  data7     |   data8  |
-----------------------------------------------------

Here, header_main_1 is the main header which encompasses two more headers sub_1 and sub_2. Similarly with header_main_2. What follows is the data. The headers are clickable so that data can be sorted etc.

Is there any component/tutorial out there which touches on such a layout? If not and if I have to create it on my own, any tips on how should I go about doing it? Is there any option on grid to trigger this behaviour?

TIA,
sasuke


Solution

  • You can span cells with the grid control. There are examples in the wxPython demo package. However, you cannot have the labels in the columns themselves span across multiple columns. I think the cell spanning will get you most of the way there though. The columns will continue to be sortable. If you want the two columns on the right to sort without affecting the columns on the left, then you'll have to add that logic yourself or create two grids and put them next to each other.