-
Notifications
You must be signed in to change notification settings - Fork 124
Code Examples
Damien Farrell edited this page Nov 9, 2017
·
4 revisions
Create a parent frame and then add the table to it:
from tkinter import *
from pandastable import Table
#assuming parent is the frame in which you want to place the table
pt = Table(parent)
pt.show()
Update the table:
#alter the DataFrame in some way, then update
pt.redraw()
Import a csv file:
pt.importCSV('test.csv')
A class for launching a basic table in a frame:
from tkinter import *
from pandastable import Table, TableModel
class TestApp(Frame):
"""Basic test frame for the table"""
def __init__(self, parent=None):
self.parent = parent
Frame.__init__(self)
self.main = self.master
self.main.geometry('600x400+200+100')
self.main.title('Table app')
f = Frame(self.main)
f.pack(fill=BOTH,expand=1)
df = TableModel.getSampleData()
self.table = pt = Table(f, dataframe=df,
showtoolbar=True, showstatusbar=True)
pt.show()
return
app = TestApp()
#launch the app
app.mainloop()
Per column formats are stored in a dictionary called columnformats
, with sub dictionaries for storing different formats. Currently only one is used for alignment, others may be added.
To set alignments:
cf = pt.columnformats['alignment']
#set a column alignment
cf['label'] = 'w'