tkintertable
tkintertable copied to clipboard
Feature request: possibility of disabling some right-click options
Hello. Thank you for great tool. I have small feature request for future versions.
I have tried to disable adding rows and deleting rows for my table and I had to do it manually by changing line in Tables.py from general = ["Select All", "Add Row(s)" , "Delete Row(s)", "Auto Fit Columns", "Filter Records", "Preferences"] to general = ["Select All", "Auto Fit Columns", "Filter Records", "Preferences"]
But it would be nice to make it possible while creating new table, for example: table = TableCanvas(some_frame, model=model, disable_add_rows=True, disable_delete_rows=True)
It would be good solution to have such parameter for every right-click option. :)
Hello @bartlomiejduda Doing something like this would help serve your purpose: TableCanvas(self.tframe,read_only=True)
The above functionality helps make your table read-only!
Hey, @hannansatopay Thanks for answer. I know read-only option, I have tested it earlier, but in my particular case I needed to disable only adding and deleting rows to prevent breaking some functionality by user. :)
Hello, It's possible but you have to make a few changes
-
On your ide navigate to
class TableCanvas(Canvas):
-
With crtl + f look for something like
rename column
it doesn't really matter the important thing is that you find the popup. You can also look fordef popupMenu(self, event):
and you will find what we are looking for just below. Note that we have twodef popupMenu(
, so changes are slightly different. -
You just have to comment on what you don't need.
-
Example
On def popupMenu(self, event, rows=None, cols=None, outside=None):
you have to change:
defaultactions = {
# "Set Fill Color" : lambda : self.setcellColor(rows,cols,key='bg'),
# "Set Text Color" : lambda : self.setcellColor(rows,cols,key='fg'),
"Copiar" : lambda : self.copyCell(rows, cols),
"Pegar" : lambda : self.pasteCell(rows, cols),
"Fill Down" : lambda : self.fillDown(rows, cols),
"Fill Right" : lambda : self.fillAcross(cols, rows),
# "Add Row(s)" : lambda : self.addRows(), THIS LINE
# "Delete Row(s)" : lambda : self.deleteRow(), THIS LINE
But you also need to change this list below:
general = [...
- If you get any errors after doing this it's because some change is missing. In
def popupMenu(self, event):
changes are slightly different as I said before.
To sum up you just have comment and change values like the ones in general = [...
for example.
Hello. Yeah, I was able to do it as I described in my first post by changing "general" list:
I have tried to disable adding rows and deleting rows for my table and I had to do it manually by changing line in Tables.py from general = ["Select All", "Add Row(s)" , "Delete Row(s)", "Auto Fit Columns", "Filter Records", "Preferences"] to general = ["Select All", "Auto Fit Columns", "Filter Records", "Preferences"]
It is only a feature request for developers to make it by parameters:
It would be good solution to have such parameter for every right-click option. :)
For me It would be safer to make such changes in my code rather than tkintertable code. :)
Yes I think since you know how to do it it's better to allow developers to sub-class the table and add this themselves. I generally am not adding new features to this package now, only bug fixes.