dmnfarrell / tkintertable Goto Github PK
View Code? Open in Web Editor NEWA pure Python library for adding tables to a Tkinter application
License: Other
A pure Python library for adding tables to a Tkinter application
License: Other
What steps will reproduce the problem?
1. Create a table with records
2. Have a window that's larger than the list of records so there is open area
3. Double click the area.
4. Exception occurs: list index of of range. name=self.reclist[rowindex]
What is the expected output? What do you see instead?
Nothing should happen when you double click somewhere without a row/column.
Original issue reported on code.google.com by [email protected]
on 17 Nov 2014 at 5:57
What steps will reproduce the problem?
1. create a default TableCanvas
2. press left arrow key until the current cell moves to the first column of any
rows different from the first row
3. the selection disappear and could not move to the previous role, exception
of IndexError is throwed
What version of the product are you using? On what operating system?
Latest version on Linux
Suggestions:
Please modify in handle_arrow_keys():
elif event.keysym == 'Left':
if self.currentcol == 0:
if self.currentrow == 0:
return
else:
self.currentcol = self.cols-1
self.currentrow = self.currentrow - 1
else:
self.currentcol = self.currentcol -1
Original issue reported on code.google.com by [email protected]
on 29 Aug 2013 at 8:25
What steps will reproduce the problem?
1. use tkintertable on Windows
2. try to export as csv
3. open the csv file in excel
What is the expected output? What do you see instead?
Expected output:
A csv file without empty lines interspersed
What happens:
An empty line follows every intended line due to an extra carriage return.
What version of the product are you using? On what operating system?
Windows 7, tkintertable v 1.1.2
Please provide any additional information below.
You should change line 147 in Tables_IO.py from
>writer = csv.writer(file(filename, "w"), delimiter=sep)
to
>writer = csv.writer(file(filename, "wb"), delimiter=sep)
Opening the file in text mode on Windows inserts an extra carriage return. See
here:
http://stackoverflow.com/questions/3348460/python-getting-rid-of-extra-line
Original issue reported on code.google.com by ballaban
on 10 Sep 2014 at 9:13
Hi,
I am trying to use your module to import some stored data and programmatically
add rows as new information comes in. I am having trouble specifying the order
of the columns as they are created.
I have modified your createData() function as:
def createData():
data = {}
serials = [ '3456', '2343', '2345' ]
colnames = [ 'Serial', 'IP', 'Name' ]
for sn in serials:
data[sn] = {}
ips = ['172.26.2.1', '172.26.2.2', '172.26.2.3']
names = ['Test1', 'Test2', 'Test3']
i=0
for sn in serials:
data[sn][colnames[0]] = serials[i]
data[sn][colnames[1]] = ips[i]
data[sn][colnames[2]] = names[i]
i+=1
return data
The problem I am finding is that the IP column is the first column, rather than
the serial number. How can I switch the order of these columns at the start of
the program?
Thanks,
Patrick
Original issue reported on code.google.com by [email protected]
on 3 Mar 2013 at 4:31
What steps will reproduce the problem?
1. Create a TableCanvas with default settings
2. Double click in area beyond the rows or columns
3. IndexError is throwed
What version of the product are you using? On what operating system?
Latest version on Linux
Suggestion: Please modify code in handle_double_click as follows:
row = self.get_row_clicked(event)
col = self.get_col_clicked(event)
if row not in range(0, self.rows) or col not in range(0, self.cols):
return
Original issue reported on code.google.com by [email protected]
on 29 Aug 2013 at 8:27
Hello I have intern issues when calling the method setCellColor(row,col,color) it triggers the following error :
NameError: name 'IntType' is not defined
It seems that it is because of python 3.6 and we use Int
instead of IntType
. However after having modified this line i had the following error : NameError: name 'Int' is not defined
so i assume that i guessed Wrong.
Here is your function :
1180 def setcellColor(self, rows, cols=None, newColor=None, key=None, redraw=True):
1181 """Set the cell color for one or more cells and save it in the model color"""
1182
1183 model = self.getModel()
1184 if newColor == None:
1185 import tkColorChooser
1186 ctuple, newColor = tkColorChooser.askcolor(title='pick a color')
1187 if newColor == None:
1188 return
1189
1190 if type(rows) is IntType:
1191 x=rows
1192 rows=[]
1193 rows.append(x)
1194 if self.allrows == True:
1195 #we use all rows if the whole column has been selected
1196 rows = range(0,self.rows)
1197 if cols == None:
1198 cols = range(self.cols)
1199 for col in cols:
1200 for row in rows:
1201 #absrow = self.get_AbsoluteRow(row)
1202 model.setColorAt(row, col, color=newColor, key=key)
1203 #setcolor(absrow, col)
1204 if redraw == True:
1205 self.redrawTable()
1206 return
I chose to delete the if Statement line 1190 in order to skip this verification knowing that when i am calling the function i give an Int for row and col attributes.
But i had an other error :
for col in cols: TypeError: 'int' object is not iterable
This function seems totally broken man
Changing font size in TableCanvas constructor. I set the thefont="Arial 8" and I get ValueError: could not convert string to float: 'r'
I changed the font to Consolas and then I get a value error with float: 'o'
empTKtable = TableCanvas(eDataFrameRIGHT, model=empModel, rowheaderwidth=0, width=425, height=16, tablewidth=600, thefont="Arial 8") empTKtable.show()
Hi,
how can i execute my own custom function when a row is deleted?
PyPi in its 1.3.1 version of tkintertable has a '1.2' version shown (it is also marked as 1.2 in __init__.py
).
Also, the 1.3.1 seems not fully compatible with the python 3 since it still has the string.lower() calls.
Code responsible for opening files:
filename=tkFileDialog.askopenfilename(defaultextension='.tbleprj"',
initialdir=os.getcwd(),
filetypes=[("Pickle file","*.tbleprj"),
("All files","*.*")],
parent=self.tablesapp_win)
despite file default extension should be .tblprj
Original issue reported on code.google.com by [email protected]
on 29 Jan 2013 at 8:52
There is no support for Python 3, even if
pip install tkintertable
only puts out some warnings.
Code crashes for some
print '...'
statements.
Original issue reported on code.google.com by [email protected]
on 18 Dec 2013 at 3:28
Hello i am facing a really weird issue,
I have a file "editorWindow2.py" which when it's called creates a tk frame containing several tableCanvas :
Everything works like a charm i can click on cells and change their values to finally export the whole thing into an xml file.
However sometimes i call the same file from an other entry point in the program but this time the cells are no more editable and i have no clues why. I have checked that i call the window with exactly the same type of objects and data as i do in the case where it works.
Here is the code :
class editionWindowModel2():
def __init__(self):
pass
class editionWindowView2():
def __init__(self,master,count):
self.frames=[]
for i in range(count):
self.frames.append(tk.Frame(master))
self.frames[i].pack(fill=tk.BOTH, expand=True)
class editionWindowController2():
def __init__(self,data,count):
self.root = tk.Tk()
self.root.geometry("1920x1200")
self.canvas=tk.Canvas(self.root)
self.container=tk.Frame(self.canvas)
self.model=editionWindowModel2()
self.view=editionWindowView2(self.container,count)
self.vsb = tk.Scrollbar(self.root, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.canvas.pack(side="left", fill=tk.BOTH, expand=True)
self.canvas.create_window(4,4,window=self.container, anchor="nw", tags="self.container")
self.container.bind("<Configure>", self.onFrameConfigure)
self.data=data
tables=[]#This variable will regroup as many table as the number of metric present in the orginal file
y=0
for metric in self.data :
x=0
tables.append(TableCanvas(self.view.frames[y],editable=True,width=1700,cellwidth=200,rows=metric.rows,cols=5,rowselectedcolor='#B0E0E6',colselectedcolor='#B0E0E6'))
colname=tables[y].model.getColumnName(4)
self.colorCol(tables[y],"#98FB98")
tables[y].model.columnwidths[colname]=1100
tables[y].show()
tables[y].model.setValueAt("Metric ID :",x,0)
#rest of the table is filled like the line above.
I precise that i am beginner with tkinter so please don't be too hard on me ahah
Let me explain more clearly : my program has two ways to be used, First user can chose to edit an xml file so he can import a file in order to edit it.
class firstWindowView():
def __init__(self,master):
self.frame = tk.Frame(master).grid(row=0,column=0,sticky="NSEW")
class firstWindowController():
def __init__(self):
self.root = tk.Tk()
self.model=firstWindowModel()
self.view=firstWindowView(self.root)
L1 = tk.Label(self.root, text = "Chose an action :").grid(row=0,column=1)
importButton=tk.Button(self.root,text="Import from XML",width=20,command=self.importXml).grid(row=0,column=2)
exportButton=tk.Button(self.root,text="Create your own",width=20,command=self.exportToXml).grid(row=1,column=2)
def run(self):
self.root.title("Raspberry Pi Data Sender")
self.root.mainloop()
def importXml(self):
self.root.destroy()
browser=XmlBrowserController()
browser.run()
def exportToXml(self):
self.root.destroy()
metricsCreator=metricsController()
metricsCreator.run()
in case where he choses "import", next window called is this one :
class XmlBrowserView():
def __init__(self,master):
self.frame = tk.Frame(master)
class XmlBrowserController():
def __init__(self):
self.root = tk.Tk()
self.model=XmlBrowserModel()
self.view=XmlBrowserView(self.root)
self.fileName=tk.StringVar()
self.fileName = fd.askopenfilename(initialdir = "../",title = "Select file")
L1 = tk.Label(self.root, text = "XML file Path : "+self.fileName).grid(row=0,column=0)
editButton=tk.Button(self.root,text="Edit",width=10,command=self.open).grid(row=0,column=1)
cancelButton=tk.Button(self.root,text="Cancel",width=10,command=self.quit).grid(row=1,column=1)
def run(self):
self.root.title("Load an XML file")
self.root.mainloop()
def open(self):
self.model.fileName=self.fileName
serializer=Serializer()
self.model.root=serializer.importFromFile(self.model.fileName)
display=displayController(self.model.root)
self.root.destroy()
display.run()
and finally
class displayView():
def __init__(self,master):
self.frame = tk.Frame(master).grid(row=0,column=0,sticky="NSEW")
class displayController():
def __init__(self,xmlElement):
self.root = tk.Tk()
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(0, weight=1)
self.model=displayModel(xmlElement)
self.tree=xmlElement
self.view=displayView(self.root)
self.fileName=tk.StringVar()
self.count=0
tree=self.prettify(xmlElement)
L1 = tk.Label(self.root,justify="left",anchor="w",text = tree).grid(row=0,column=0,sticky="NSEW")
saveButton2=tk.Button(self.root,text="Edit",width=10,command=self.save2).grid(row=self.count+2,column=0)
cancelButton=tk.Button(self.root,text="Cancel",width=10,command=self.quit).grid(row=self.count+1,column=0)
def save2(self):
root=self.model.xmlElement
metricsTable=[]
count=1
testCounter=0
for metric in root.findall("{http://standards.iso.org/iso-iec/19086/-2/ed-1/en}Metric"):
testCounter+=1
count+=1
params=[]
rules=[]
metricRefs=[]
expressions=[]
m=Metric(metric.get('id'),metric.get('source'),metric.get('scale'),metric.get('description'),metric.get('note'),metric.get('category'))
for param in metric.findall('{http://standards.iso.org/iso-iec/19086/-2/ed-1/en}Parameter'):
p=Parameter(param.get('id'),param.get('parameterStatement'),param.get('unit'),param.get('description'),param.get('note'))
params.append(p)
for expression in metric.findall('{http://standards.iso.org/iso-iec/19086/-2/ed-1/en}Expression'):
e=Expression(expression.get('id'),expression.get('expressionStatement'),expression.get('expressionLanguage'),expression.get('description'),expression.get('note'),expression.get('unit'))
expressions.append(e)
for rule in metric.findall('{http://standards.iso.org/iso-iec/19086/-2/ed-1/en}Rule'):
r=Rule(rule.get('id'),rule.get('ruleStatement'),rule.get('ruleLanguage'),rule.get('description'),rule.get('note'))
rules.append(r)
for ref in metric.findall('{http://standards.iso.org/iso-iec/19086/-2/ed-1/en}UnderlyingMetricRef'):
reference=UnderlyingMetricRef(ref.get('refid'))
metricRefs.append(reference)
m.parameters=params
m.rules=rules
m.underlyingMetrics=metricRefs
m.expression=expressions
m.rows=self.metricRowsCounter(metric,m)
metricsTable.append(m)
#print(type(metricsTable))
#print(metricsTable)
self.root.destroy()
editor=editionWindowController2(metricsTable,count)
editor.run()
and the last window called is the one i first showed you with the tkintertable.
the other use case changes only in the first windows :
class metricsView():
def __init__(self,master):
self.frame = tk.Frame(master)
class metricsController():
def __init__(self):
self.root = tk.Tk()
self.model=metricsModel()
self.view=metricsView(self.root)
self.metricList=[]
newMetricButton=tk.Button(self.root,text="Add a new metric",width=20,command= lambda : self.newMetric(self.metricList)).grid(row=0,column=0)
printButton=tk.Button(self.root,text="Print your file",width=20,command= lambda : self.toString(self.metricList)).grid(row=0,column=1)
saveButton=tk.Button(self.root,text="Save",width=20,command=lambda:self.save(self.metricList)).grid(row=0,column=2)
cancelButton=tk.Button(self.root,text="Quit",width=20,command=self.cancel).grid(row=0,column=3)
def run(self):
self.root.title("Metrics Creator")
self.root.mainloop()
def toString(self,metrics):
xmlTree=self.treeBuilder(metrics)
print(type(xmlTree))
display=displayController(xmlTree)
display.run()
and at this point the display is called with an object of the same type as it is in the first case.
I runed Freeze.py and it got an error as follows:
Traceback (most recent call last):
File "D:/pythonTable/tkintertable-master/Application/freeze.py", line 28, in <module>
f() # runs the freezing process
File "D:\Program Files\anaconda\lib\site-packages\bbfreeze\freezer.py", line 593, in __call__
if not self._handleRecipes():
File "D:\Program Files\anaconda\lib\site-packages\bbfreeze\freezer.py", line 483, in _handleRecipes
if x(self.mf):
File "D:\Program Files\anaconda\lib\site-packages\bbfreeze\recipes.py", line 236, in recipe_matplotlib
mf.import_hook("matplotlib.numerix.random_array", m)
File "D:\Program Files\anaconda\lib\site-packages\bbfreeze\modulegraph\modulegraph.py", line 257, in import_hook
m = self.load_tail(q, tail)
File "D:\Program Files\anaconda\lib\site-packages\bbfreeze\modulegraph\modulegraph.py", line 341, in load_tail
raise ImportError, "No module named " + mname
ImportError: No module named matplotlib.numerix
'''
Importing from a text file can be down interactively from the GUI by right clicking on the table and choosing 'Import Table' from the popup menu.
'''
By right click the gui,we can import data from text file.
Can I import data from a text file by the function?
I am attempting to determine if there's a means to provide a column in a table and hide it, following with resizing the displayed table to match the remaining columns.
Hiding the column "Pos" (but table is sized incorrectly):
I have tried numerous methods but just cannot get the table size to shrink. Code:
import Tkinter`
#import tkintertable
from tkintertable import TableModel, TableCanvas
# ------------------------------------------------------------------------
# Start the main frame
# ------------------------------------------------------------------------
CAN_WIDTH = 1100
CAN_HEIGHT = 1100
app = Tkinter.Tk()
app.title('test_tkintertable')
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(0, weight=1)
# Make a canvas in which the frame will rest
CANVAS = Tkinter.Canvas(app)
CANVAS.grid(row=0, column=0, sticky="nsew")
CANVAS.configure(scrollregion=(0, 0, CAN_WIDTH, CAN_HEIGHT))
# Make a scrollbar attached to window - it will move the canvas
V_SCROLL = Tkinter.Scrollbar(app, orient='vertical')
V_SCROLL.config(command=CANVAS.yview)
CANVAS.config(yscrollcommand=V_SCROLL.set)
H_SCROLL = Tkinter.Scrollbar(app, orient='horizontal')
H_SCROLL.config(command=CANVAS.xview)
CANVAS.config(xscrollcommand=H_SCROLL.set)
# Place the scrollbar in grid
V_SCROLL.grid(row=0, column=30, sticky='ns')
H_SCROLL.grid(row=1, column=0, sticky='ew')
# Make the frame that will hold the widgets
FRAME = Tkinter.Frame(CANVAS, bd=0, relief='sunken')
FRAME.config(width=CAN_WIDTH, height=CAN_HEIGHT)
FRAME.grid(row=0, column=0)
# All other widgets will go in the frame
CANVAS.create_window(0, 0, window=FRAME, anchor="nw")
# Make a model
pricing_model = TableModel()
# Predefine the column order in the model before adding data
columns = ['Pos', 'Pool', 'Price']
for column in columns:
pricing_model.addColumn(column)
celldata = {'Item A': {'Pos':0, 'Pool':100, 'Price':10},
'Item B': {'Pos':1, 'Pool': 200, 'Price':0},
'Item C': {'Pos':2, 'Pool': 50, 'Price':5}
}
# Add the data using the data dictionary
pricing_model.importDict(celldata)
keys = celldata.keys()
num_cols = len(celldata[keys[0]])
num_rows = len(keys)
height_of_row = 30
colwidth = 50
table_width = colwidth * num_cols
table_height = 500
# Create the spreadsheet
table_height = height_of_row * num_rows
ssheet = TableCanvas(FRAME, model=pricing_model,
width=table_width, height=table_height,
cellwidth=colwidth, cellbackgr='#E3F6CE',
rowheight=height_of_row, editable=True,
rowselectedcolor='yellow',reverseorder=0,
rowheaderwidth=50, showkeynamesinheader=True)
ssheet.createTableFrame()
# Fill in the non-stored column widths
for column in columns:
pricing_model.columnwidths[column]=colwidth
# Sort rows in order of values in colindex column after table created
columns_in_table = pricing_model.columnNames
print 'columns_in_table = ', columns_in_table
colindex = columns_in_table.index('Pos')
ssheet.sortTable(columnIndex=colindex)
# TEST #1:
# Hide the sorting column and resize the table
pricing_model.columnwidths['Pos'] = 0
pos = ssheet.col_positions
print "pos =", pos
cols = ssheet.cols
print "cols = ", cols
widths = pricing_model.columnwidths
print "widths = ", widths
num_cols = num_cols - 1
table_width = colwidth * num_cols
ssheet.width = 50
ssheet.redrawTable()
# ------------------------------------------------------------------------
# Run the message-processing loop
# ------------------------------------------------------------------------
app.mainloop()
Hello i noticed the exportation method doesn't work for python 3 and more, i have modified your file in order to make it work for both python2.7 and 3 :
def ExportTableData(self, table, sep=None):
"""Export table data to a comma separated file"""
parent=table.parentframe
filename = filedialog.asksaveasfilename(parent=parent,defaultextension='.csv',
filetypes=[("CSV files","*.csv")] )
if not filename:
return
if sep == None:
sep = ','
f=open(filename, "w")
writer = csv.writer(f,delimiter=sep)
model=table.getModel()
recs = model.getAllCells()
#take column labels as field names
colnames = model.columnNames
collabels = model.columnlabels
row=[]
for c in colnames:
row.append(collabels[c])
writer.writerow(row)
for row in recs.keys():
writer.writerow(recs[row])
f.close()
return
What steps will reproduce the problem?
1. Just use the first 2 import statements
2.
3.
What is the expected output? What do you see instead?
Expect: Goodness
Actual:
Traceback (most recent call last):
File "C:\Python32\tbvpython\tkintertable_test1.py", line 5, in <module>
from tkintertable.Tables import TableCanvas
File "C:\Python32\lib\site-packages\tkintertable-1.1.2-py3.2-win32.egg\tkintertable\Tables.py", line 560
print 'found in',row,col
^
SyntaxError: invalid syntax
What version of the product are you using? On what operating system? 1.1.2
against Python32 on windows XP machine
Please provide any additional information below.
tkinter works with no problem
Original issue reported on code.google.com by [email protected]
on 23 Oct 2013 at 12:45
When I do stuff with my mouse over an empty table (with columns but without rows) I get all kinds of exceptions. Probably some values are only initialized, when there is at least one cell to show.
Mouseover, left mouse click, left mouse release, right mouse click and mouse drag throw uncaught exceptions. Nothing bad happens, but it seems to me it would be nicer without exceptions. This seems similar to some of the exceptions of #15.
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
return self.func(*args)
File "/home/lanpirot/.local/lib/python2.7/site-packages/tkintertable/Tables.py", line 2433, in handle_mouse_move
if x > self.tablewidth+w:
AttributeError: ColumnHeader instance has no attribute 'tablewidth'
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
return self.func(*args)
File "/home/lanpirot/.local/lib/python2.7/site-packages/tkintertable/Tables.py", line 2353, in handle_left_click
if self.atdivider == 1:
AttributeError: ColumnHeader instance has no attribute 'atdivider'
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
return self.func(*args)
File "/home/lanpirot/.local/lib/python2.7/site-packages/tkintertable/Tables.py", line 2370, in handle_left_release
if self.atdivider == 1:
AttributeError: ColumnHeader instance has no attribute 'atdivider'
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
return self.func(*args)
File "/home/lanpirot/.local/lib/python2.7/site-packages/tkintertable/Tables.py", line 2448, in handle_right_click
self.handle_left_click(event)
File "/home/lanpirot/.local/lib/python2.7/site-packages/tkintertable/Tables.py", line 2353, in handle_left_click
if self.atdivider == 1:
AttributeError: ColumnHeader instance has no attribute 'atdivider'
What steps will reproduce the problem?
1. go to usage
2. copy and paste imports
3. traceback says no pmw
What is the expected output? What do you see instead?
is it supposed to depend on pmw? I didn't see that in the documentation.
What version of the product are you using? On what operating system?
1.1.2
Please provide any additional information below.
I used pip install tkintertable
Original issue reported on code.google.com by [email protected]
on 27 Jun 2013 at 8:55
What steps will reproduce the problem?
Let's say you have a TableModel called tableModel with 10 rows:
-call tableModel.deleteRows(0,10)
or
- select all the rows with GUI and delete them through the popup dialog
clicking on "Delete Row(s)"
What is the expected output? What do you see instead?
I would expect the rows not to be visible anymore, but they are still visible,
even if unresponsive to user action, like clicking on them.
What version of the product are you using? On what operating system?
tkintertable-1.1.2, Linux Mint 15 (Ubuntu 13.04)
Please provide any additional information below.
If new rows are inserted, the content of the table is displayed correctly.
The problem appears only if you delete all the rows, not just one or a subset
of the total rows.
Original issue reported on code.google.com by [email protected]
on 18 Mar 2014 at 8:18
Hi
I'm using tkinertable and want to change the text in a cell, or better the whole row to bold.
Couldn't find anything in the web.
How can I do this?
Thx for your support!
Hey, thanks for the great tool!
My problem is a small one: if I pass ImportDict()
a (sorted) OrderedDict()
object, this order is not remembered when I load up the 'spreadsheet'.
I was thinking, perhaps wherever this sorting happens in the code, it'd be possible to just typecheck the dict object that's being passed in. If it's dict
, do as normal. If it's an OrderedDict
, the user must already have the proper order determined, so it could be left unsorted.
Cheers!
Always prints "loading prefs from [filename]" at startup. This should be
suppressed by default.
Original issue reported on code.google.com by ddruckerccn
on 25 Nov 2013 at 6:08
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Python36-32\lib\site-packages\tkintertable\__init__.py", line 24, in <module>
from Tables import *
ModuleNotFoundError: No module named 'Tables'
Working with Python 3.7 using tkintertable I fount that titlerows= has no effect.
There is always one, despite of the figure I give.
Since titlerows= is not producing an error, I thought it should work.
having modify all the codes following all suggestions on this site.
This is the code that I ran
$python3 test.py
import tkinter as tk
from Tables import TableCanvas
from TableModels import TableModel
root = tk.Tk()
tframe = tk.Frame(root)
tframe.pack()
table = TableCanvas(tframe)
table.createTableFrame()
root.mainloop()
This code will crash when I put two fingures on mac touchpad, and move.
I have checked those code in Tables.py
This is the do_binding(self) method
def do_bindings(self):
"""Bind keys and mouse clicks, this can be overriden"""
self.bind("<Button-1>",self.handle_left_click)
self.bind("<Double-Button-1>",self.handle_double_click)
self.bind("<Control-Button-1>", self.handle_left_ctrl_click)
self.bind("<Shift-Button-1>", self.handle_left_shift_click)
self.bind("<ButtonRelease-1>", self.handle_left_release)
if self.ostyp=='mac':
#For mac we bind Shift, left-click to right click
self.bind("<Button-2>", self.handle_right_click)
self.bind('<Shift-Button-1>',self.handle_right_click)
else:
self.bind("<Button-3>", self.handle_right_click)
self.bind('<B1-Motion>', self.handle_mouse_drag)
self.bind('<Motion>', self.handle_motion)
self.bind_all("<Control-x>", self.deleteRow)
self.bind_all("<Control-n>", self.addRow)
self.bind_all("<Delete>", self.clearData)
self.bind_all("<Control-v>", self.paste)
#if not hasattr(self,'parentapp'):
# self.parentapp = self.parentframe
self.parentframe.master.bind_all("<Right>", self.handle_arrow_keys)
self.parentframe.master.bind_all("<Left>", self.handle_arrow_keys)
self.parentframe.master.bind_all("<Up>", self.handle_arrow_keys)
self.parentframe.master.bind_all("<Down>", self.handle_arrow_keys)
self.parentframe.master.bind_all("<KP_8>", self.handle_arrow_keys)
self.parentframe.master.bind_all("<Return>", self.handle_arrow_keys)
self.parentframe.master.bind_all("<Tab>", self.handle_arrow_keys)
#if 'windows' in self.platform:
self.bind("<MouseWheel>", self.mouse_wheel)
self.bind('<Button-4>', self.mouse_wheel)
self.bind('<Button-5>', self.mouse_wheel)
self.focus_set()
return
Any suggestions ?????
When two same tables of same dimension are shown in same page, their data gets interchanged after scrolling one table. Note that both the tables are redrawn in a single function and the table last redrawn inflects its data on the other one.
This image if of both the tables before using scrolling in any table
After scrolling in table on left side, data from right table id displayed in this one also. Table lastly redrawn is the one on right side.
Apparently not Python 3.x ready but probably something wrong with the metadata as it installs for Python 3.x using pip from the cheese shop.
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkintertable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pavlix/.local/lib/python3.6/site-packages/tkintertable/__init__.py", line 24, in <module>
from Tables import *
ModuleNotFoundError: No module named 'Tables'
@dmnfarrell
Don't know if it's a bug, but: I can't disable/enable the table from the code when I think the user shoulden't be able to Change the table.
Any idea?
hi, good morning...
I am trying to build a table from csv file, and it worked at the first load.
The problem is when the csv file is changed, I want the table is redraw with the new data, But its not change at all...
how do I redraw the table? i use table.redrawTable() but its not working...
thankyou
What steps will reproduce the problem?
1. Create a normal TableCanvas with rows and height set to larger values (say
30*20)
2. Click window maximize button
3. The contents of TableCanvas outside the initial window range are not
properly displayed in the maximized window.
What is the expected output? What do you see instead?
All the contents should be properly displayed.
What version of the product are you using? On what operating system?
Latest. Linux
Please provide any additional information below.
Suggestions: in TableCanvas.createTableFrame() add:
# Fix the bug of not being properly redrawn during maximizing
# the default behavior only bind <Configure> event for
# the parent frame BUT NOT for the inherited Canvas class.
self.bind('<Configure>', lambda event: self.redrawTable())
Original issue reported on code.google.com by [email protected]
on 29 Aug 2013 at 3:13
What steps will reproduce the problem?
1. Create a table
2. Add data with a new line
3. Data trails off the bottom edge.
What is the expected output? What do you see instead?
I expected row height to be increased when specific rows need it. That is, rows
with three lines of data in an entry will be three times as tall, while the
remaining rows will still be only one line tall.
Sorry if this isn't the right venue, I couldn't find a better way to e-mail you
guys.
Original issue reported on code.google.com by [email protected]
on 17 Nov 2014 at 5:41
Hi,
I've just found this and it is really well done! I am confused on how to intialize the TableCanvas object with data. I saw the part in the README for updating, but either I am not understanding it right or when I do it as shown in the section it appends my data to the end of the existing model in the object. I want to replace the data in the sheet with my new model so the next logical step would be to pass it in with the TableClass object creation, but I am not sure of the required data structure for the class to utilize the data fully.
Could you outline the base data structure for passing in data into the TableCanvas constructor?
I'm attempting to get long text to appear in a cell. From the data file:
The text has embedded newlines (0x0a) which appear to work,
and the data appears to be going into the model correctly,
but (as seen in the second and third images) the displayed info is being truncated. Is there anything that can be done with that?
Hey @dmnfarrell !
Great library! How can I change the row labels. There is a func. to change column label but I dont see any for rows...
Thanks!
Hi, Tkintertable looks like a great tool, but i seem to have a problem importing a dict from mysql.
After fetching it from mysql, my dict (ret2) looks like this:
print(ret2)
({'Kundenkonto': 10000L, 'BUKey': 3L, 'Umsatz': 99.99, 'Sachkonto': 8400L, 'Kundenname': 'TEST', 'UstID': '', 'Rechnungsdatum': None, 'Belegtext': 'Rakuten Bestell-Nr.: 111-222-333', 'PDF': None, 'Belegfeld2': '0', 'MwSt': 19L, 'Waehrung': 'EUR', 'Rechnungsnummer': 'RE1000'}, and so on
model = table.model
model.importDict(ret2)
table.redrawTable()
TypeError: tuple indices must be integers, not dict
What am I missing?
Thank you
Hello! I would like to add column with type DropDownList. Tell me please where it I can add in your code ?
C:\Users\kig0pkt12\AppData\Local\Programs\Python\Python37\python.exe C:/Code/test_project/test.py
Traceback (most recent call last):
File "C:/Code/LeM_Test/P208_ASU_GUI/test.py", line 12, in <module>
rowselectedcolor='yellow',reverseorder=1)
File "C:\Users\kig0pkt12\AppData\Local\Programs\Python\Python37\lib\site-packages\tkintertable\Tables.py", line 60, in __init__
self.ostyp = self.checkOSType()
File "C:\Users\kig0pkt12\AppData\Local\Programs\Python\Python37\lib\site-packages\tkintertable\Tables.py", line 2243, in checkOSType
ostyp = string.lower(os.environ[var])
AttributeError: module 'string' has no attribute 'lower'
unable to make a cell Readonly
first thanks for this great program
second i am beginner in python and tkinter i faced with this bugs when trying
to use the python 3 version of tkintertable and this my try
to fix them so if there is something wrong i am sorry for any misunderstanding
i use python 3.4.2 , windows xp
--------------------------------------------------
1-
in the first after loading the table in it's parent frame i got this error in
File Tables.py line 2143, in checkOSType
ostyp=string.lower(os.environ[var])
AttributeError: 'module' object has no attribute 'lower'
i fix it by make change from using srting to str
in line 2143 in Tables.py change the line from:
ostyp=string.lower(os.environ[var])
to:
ostyp=str.lower(os.environ[var])
-----------------------------------------
2-
the reason of this bug is moving the mouse over an empty place on the table it
raise TypeError in the handle_motion function in Table.py module in line 1032
if 0 <= row < int(self.rows) and 0 <= col < self.cols:
this happen if i move the mouse over an empty place that have no
columns in it and if we use python 2 it did't give me this error the reason
for that is in python 2 when we compare two value one of them is None like
1 < None it will give us the result of comparison False but in python 3 it
raise a TypeError so if i move the mouse over an empty place on the table
it make one of the event coordinate None so it make comparison with None type
and integer type
to fix this error i catch it through try except statement like this:
try:
if 0 <= row < int(self.rows) and 0 <= col < self.cols:
self.drawTooltip(row, col)
except TypeError:
return
return
-----------------------------------------------------------
3-
this bug raise if i specified column label bigger than 12 characters
Traceback (most recent call last):
File "F:\4\test\python\3\test.py", line 28, in <module>
set_income_table()
File "F:\4\test\python\3\test.py", line 24, in set_income_table
table.createTableFrame()
File "F:\4\test\python\3\tkintertable\Tables.py", line 218, in createTableFrame
self.redrawTable(callback=callback)
File "F:\4\test\python\3\tkintertable\Tables.py", line 330, in redrawTable
self.redrawVisible(event, callback)
File "F:\4\test\python\3\tkintertable\Tables.py", line 316, in redrawVisible
self.tablecolheader.redraw()
File "F:\4\test\python\3\tkintertable\Tables.py", line 2222, in redraw
collabel=collabel[0:int(w)/12]+'.'
TypeError: slice indices must be integers or None or have an __index__ method
in Tables.py file in line 2222 in the redraw function if the column label
is bigger than 12 character it will give me the former error the reason for
that is the division section in this line
collable=collabel[0:int(w)/12]+'.'
because the result of the division int(w)/12 will be float number in python 3
and this raise the former error so the fix to this error to change the division
to floor division or integer
division so the line will be like this:
collable=collable[0:int(w)//12]+'.'
---------------------------------------------------------------
4-
this error raise if i left click any empty space to the right of the table but
it will not appear if this empty place was down the last row it only appear if
i click the empty space to the right of table rows in the none columns space it
will raise type error like the one appear in the one i mention in number 2 and
appear like this
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "F:\4\test\python\3\tkintertable\Tables.py", line 863, in handle_left_click
if 0 <= rowclicked < self.rows and 0 <= colclicked < self.cols:
TypeError: unorderable types: int() <= NoneType()
and the reason for this bug is the way python 3 handle the comparisons if i
compare None with integer it will not return with false but raise a TypeError
and i fixed it by use try catch statement with the if block in code from line
862 to 871 like this:
i change it from:
if 0 <= rowclicked < self.rows and 0 <= colclicked < self.cols:
self.setSelectedRow(rowclicked)
self.setSelectedCol(colclicked)
self.drawSelectedRect(self.currentrow, self.currentcol)
self.drawSelectedRow()
self.tablerowheader.drawSelectedRows(rowclicked)
coltype = self.model.getColumnType(colclicked)
if coltype == 'text' or coltype == 'number':
self.drawCellEntry(rowclicked, colclicked)
return
to be like this:
try:
if 0 <= rowclicked < self.rows and 0 <= colclicked < self.cols:
self.setSelectedRow(rowclicked)
self.setSelectedCol(colclicked)
self.drawSelectedRect(self.currentrow, self.currentcol)
self.drawSelectedRow()
self.tablerowheader.drawSelectedRows(rowclicked)
coltype = self.model.getColumnType(colclicked)
if coltype == 'text' or coltype == 'number':
self.drawCellEntry(rowclicked, colclicked)
except TypeError:
return
return
------------------------------------------------------------------------------
5-
this bug appear if i click of Preferences menu item to show the preferences
window it will not show
the window and raise _tkinter.TclError like this:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "F:\4\test\python\3\tkintertable\Tables.py", line 1802, in showtablePrefs
self.prefswindow.geometry('+%s+%s' %(x+w/2,y+h/2))
File "C:\Python34\lib\tkinter\__init__.py", line 1669, in wm_geometry
return self.tk.call('wm', 'geometry', self._w, newGeometry)
_tkinter.TclError: bad geometry specifier "+418.0+301.5"
and this one also like bug number three the reason for it is the way python 3
handle division so in showtablPrefs in Tables.py module in line 1802
self.prefswindow.geometry('+%s+%s' %(x+w/2,y+h/2))
to fix it i change the divison from float divison to floor or integer division
like this
self.prefswindow.geometry('+%s+%s' %(x+w//2,y+h//2))
-----------------------------------------------------------------------
6-
this bug present if i call the File-->New context menu it will raise this
NameError
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "F:\4\test\python\3\tkintertable\Tables.py", line 2086, in new
parent=self.parentframe)
File "F:\4\test\python\3\tkintertable\Dialogs.py", line 97, in __init__
if labels != None and types != NoneType:
NameError: name 'NoneType' is not defined
the reason for it that in python 2 you use the Tkinter.NoneType that present in
the Tkinter library but and that already inhered from the type library but this
NoneType no longer exist in python 3 and also in tkinter so i fix it by calling
type(None) instead of explicit NoneType so i change line 97 in Dialogs.py
module in the __init__ method from this:
if labels != None and types != NoneType
into this:
if labels != None and types != type(None)
i got this from dive into python 3 book appendix a. Porting Code to Python 3
with 2to3
---------------------------------------------------------
and i upload the two files Tables.py and Dialogs.py after fixing this error on
them may be if you like to add them to the program for any future release and
thanks again for this great tool...
Karim Reefat
Original issue reported on code.google.com by [email protected]
on 17 Feb 2015 at 2:41
Attachments:
What steps will reproduce the problem?
1. ran testing.py that came with the package.
2. deleted all rows except the last one from the table. Then removed the last
one.
3. Last one doesnt get deleted. It remain in the table. Once you add new row it
gets cleared from the view.
What is the expected output? What do you see instead?
the last entry should be delete. last entry doesnt get deleted.
What version of the product are you using? On what operating system?
tkintertable (1.1.2) ( windows 7 64 bit
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 19 Mar 2014 at 4:39
Hi everyone,
I have found a bug when I try to create cx_freeze .exe file.
For example, I have 2 files: app.py
and setup.py
Inside of app.py
from Tkinter import *
from tkFileDialog import askopenfilename
from tkintertable.Tables import TableCanvas
from tkintertable.TableModels import TableModel
.
.
.
window = Tk()
window.mainloop()
When I compile this using python it runs perfectly.
Notice that I have only called the library and I am not using it.
Now I want to create an .EXE
file using cx_Freeze.
from cx_Freeze import setup,Executable
includes = []
excludes = []
packages = []
filename = "app.py"
exe = Executable(
script = "app.py",
base = 'Win32GUI',
targetName = "app.exe",
icon = 'icon.ico'
)
setup(
name = 'App',
version = '0.1',
description = 'App description',
author = 'author',
author_email = '[email protected]',
options = {'build_exe': {'excludes':excludes,'packages':packages,'includes':includes}},
executables = [exe])
The error occurs when I open the .exe
file. This happens:
There are an error with PMW loader.
I really dont know what I have to do. Is it PMW error? or is a tkintertable bug?
Thanks.
how to initial a special size table by a function ? for example ,I would like to design 4*10 table,all grids in table are empty.
ostyp = string.lower(os.environ[var])
AttributeError: module 'string' has no attribute 'lower'
self.top = Toplevel(master)
self.rows = len(pickers)
data = {'rec1': {'col1': 99.88, 'col2': 108.79, 'label': 'rec1'},
'rec2': {'col1': 99.88, 'col2': 108.79, 'label': 'rec2'}}
self.table = TableCanvas(self.top, data=data, rows=self.rows, columns=3)
self.table.show()
self.table.redraw()
it's not a bug. Is only a recomendation about a great tablelist widget written in tcl, that has low python wrapper support.
Please see the great and complete functionality... It works great.
Maybe it could give you ideas about your widget.
Thanks.
Would it be possible to implement the following?
I would like to use the tkintertable in a read only mode, where users can only scroll through the table (and highlight a row).
For this right-clicking the table should have no effect. Left clicking on the scrollbar works as expected. Left clicking the table has no effect or only highlights the clicked row.
I'm trying to get py2app to work with a dependency on tkintertable.
It fails. Please fix!
because the items in python dictionary are not ordered in the order that they're inserted, the rows and columns are not ordered if tablemodel with dictionary is used. the author may consider use an advanced dictionary data structure.
Hi,
when I run the sample code in Python 3, I got this error message.
ostyp = string.lower(os.environ[var])
AttributeError: module 'string' has no attribute 'lower'
from tkintertable import TableCanvas, TableModel
from tkinter import *
import random
from collections import OrderedDict
data = {'rec1': {'col1': 99.88, 'col2': 108.79, 'label': 'rec1'},
'rec2': {'col1': 99.88, 'col2': 321.79, 'label': 'rec3'},
'rec3': {'col1': 29.88, 'col2': 408.79, 'label': 'rec2'}
}
from tkintertable.Testing import sampledata
data=sampledata()
#print(data)
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('800x500+200+100')
self.main.title('Test')
f = Frame(self.main)
f.pack(fill=BOTH,expand=1)
table = TableCanvas(f, data=data)
table.importCSV('test.csv')
print (table.model.columnNames)
#table.model.data[1]['a'] = 'XX'
#table.model.setValueAt('YY',0,2)
table.show()
return
app=TestApp()
app.mainloop()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.