Skip to content

Commit fded89b

Browse files
authored
Update README.md
1 parent 266285e commit fded89b

1 file changed

Lines changed: 1 addition & 131 deletions

File tree

README.md

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -19,137 +19,7 @@ git clone https://github.com/dmnfarrell/tkintertable.git
1919

2020
## Usage
2121

22-
### Import the class
23-
24-
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'},
67-
'rec2': {'col1': 99.88, 'col2': 108.79, 'label': 'rec2'}
68-
}
69-
```
70-
Each record corresponds to a row in the dictionary. Columns will be created for each child key found in each record.
71-
72-
Then provide this dict to the constructor:
73-
```
74-
table = TableCanvas(frame, data=data)
75-
```
76-
77-
Or we get a handle on the model (or we can create the model first and supply it as an argument to the table constructor):
78-
```
79-
model = table.model
80-
model.importDict(data)
81-
table.redraw()
82-
```
83-
84-
### Importing from a text file
85-
```
86-
table.importCSV(filename, sep=',')
87-
```
88-
89-
This can also be done interactively from the GUI by right clicking on the table and choosing 'Import Table' from the popup menu.
90-
91-
### Sort the table
92-
```
93-
#by column name
94-
table.sortTable(columnName='label')
95-
#by column index
96-
table.sortTable(columnIndex=1)
97-
```
98-
99-
### Add and delete rows and columns
100-
101-
If column names are not given in the argument then a dialog will pop up in the GUI asking for the name which will likely not be what you want.
102-
```
103-
#add with automatic key
104-
table.addRow()
105-
#add with named key, other keyword arguments are interpreted as column values
106-
table.addRow(keyname, label='abc')
107-
#same as above with dict as column data
108-
table.addRow(keyname, **{'label'='abc'})
109-
table.addColumn(colname)
110-
#delete rows
111-
table.deleteRows(range(0,2))
112-
```
113-
114-
### Change data in individual cells
115-
116-
Simply get a handle on the table model dict and alter the data attribute (a dictionary) directly, then redraw the table.
117-
```
118-
data = table.model.data
119-
cols = table.columnNames #get the current columns
120-
data[row][col] = value #use row and column names, not cell coordinates
121-
table.model.setValueAt(value,rowindex,colindex) ##use cell coords
122-
table.redrawTable()
123-
```
124-
125-
### Change column labels
126-
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.
133-
```
134-
table = TableCanvas(master, model, rowheaderwidth=100, showkeynamesinheader=True)
135-
You can hide the row header by setting rowheaderwidth=0.
136-
```
137-
### Set preferences
138-
Preferences for the table can be set on the constructor method, for example:
139-
```
140-
TableCanvas(frame, model=model,
141-
cellwidth=50, cellbackgr='#E3F6CE',
142-
thefont="Arial 10",rowheight=16,editable=False,
143-
rowselectedcolor='yellow',reverseorder=1)
144-
```
145-
Or can be loaded later from an external preferences file:
146-
```
147-
preferences=Preferences('TablesApp')
148-
table.loadPrefs(preferences)
149-
Save and load from a file
150-
table.save('test.table')
151-
table.load('test.table')
152-
```
22+
See the [wiki](https://github.com/dmnfarrell/tkintertable/wiki/Usage) for how to use the table in Python.
15323

15424
## See also
15525

0 commit comments

Comments
 (0)