You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The core classes are TableCanvas and TableModel. You will likely want to access the TableModel class
25
-
to alter the data programmatically, otherwise the TableCanvas class is all that's required to add to the GUI.
26
-
To import:
27
-
28
-
```
29
-
from tkintertable import TableCanvas, TableModel
30
-
```
31
-
or
32
-
```
33
-
from tkintertable.Tables import TableCanvas
34
-
from tkintertable.TableModels import TableModel
35
-
```
36
-
37
-
### Create tables
38
-
39
-
To create a table, you typically create a frame in your applications GUI and provide this to the table
40
-
constructor. Note that the createTableFrame method is used to add the table to the parent frame,
41
-
so avoid using the pack or grid methods.
42
-
```
43
-
tframe = Frame(master)
44
-
tframe.pack()
45
-
table = TableCanvas(tframe)
46
-
table.show()
47
-
```
48
-
49
-
We can also create a model from some data, then use that model to initiate the table:
50
-
```
51
-
model = TableModel()
52
-
table = TableCanvas(frame, model=model)
53
-
```
54
-
55
-
### Update the table
56
-
57
-
This needs to be called to update the display after programmatically changing the table contents:
58
-
```
59
-
table.redraw()
60
-
```
61
-
62
-
### Get data into the table
63
-
64
-
It is possible to populate the tables by importing data from a csv file or creating a python dictionary. To import from a dictionary, it should be of the form:
65
-
```
66
-
data = {'rec1': {'col1': 99.88, 'col2': 108.79, 'label': 'rec1'},
Column labels can be changed programmatically by accessing the columnlabels attribute of the table model:
127
-
```
128
-
table.model.columnlabels[colname] = newlabel
129
-
```
130
-
131
-
### Row headers
132
-
The row header displays the row index number by default, but it can be used to show the row/record key names if necessary. You may also want to set the row header width to something larger than the default (40). Both these options are supplied in the constructor.
0 commit comments