0

This is my data frame

    Date    name    count
0   2015-01-02  Adam    1
1   2015-02-02  David   1
2   2015-02-02  Adam    1
3   2015-03-02  David   2
4   2015-03-02  Hardik  1
5   2015-03-01  David   2

With this data frame I have created and displayed data in a table using tkintertable.

from tkinter import *
from tkinter import ttk
from tkintertable.Tables import TableCanvas
from tkintertable.TableModels import TableModel
import pandas
import matplotlib
from matplotlib import pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
import mplcursors

master=Tk()
master.title("Data and Graph")
tabControl = ttk.Notebook(master)
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tabControl.add(tab1, text ='Tab 1')
tabControl.add(tab2, text ='Tab 2')
tabControl.pack(expand = 1, fill ="both")
ttk.Label(tab1, text ="Data").pack()
ttk.Label(tab2, text ="Graph").pack()
tframe = Frame(tab1)
tframe.pack(fill='both')
data = {'Date': {1: '2015-01-02 00:00:00', 2: '2015-01-02 00:00:00', 4: '2015-01-02 00:00:00', 6: '2015-03-02 00:00:00', 5: '2015-08-02 00:00:00', 0: '2015-10-02 00:00:00', 3:'2015-12-02 00:00:00'}, 'Alarm': {1: 'David', 2: 'Adam', 4: 'David', 6: 'David', 5: 'Hardik', 0: 'Adam', 3: 'Adam'}, 'Case': {1: 4, 2: 4, 4: 6, 6: 4, 5: 2, 0: 1, 3: 0}, 'Alarm count': {1: 2, 2: 1, 4: 2, 6: 1, 5: 1, 0: 1, 3: 1}, 'Case count': {1: 2.0, 2: 1.0, 4: 2.0, 6: 1.0, 5: 1.0, 0: 1.0, 3: 0.0}, 'Month/Year': {1: 'Jan-2015', 2: 'Jan-2015', 4: 'Jan-2015', 6: 'Mar-2015', 5: 'Aug-2015', 0: 'Oct-2015', 3: 'Dec-2015'}}
model = TableModel()
table = TableCanvas(tframe, model=model)
table.createTableFrame()
model = table.model
model.importDict(data,) #can import from a dictionary to populate model

def update_data(event=None):
    global data
    global model

fg2 = plt.figure(figsize=(15, 8), dpi=100)
fg2.add_subplot(111)
fg2.text(0.3, 0.7, 'Doosan Fuel Cell Confidential', fontsize=25, color='gray', ha='center',va='center', rotation=35, alpha=0.5)
codes_str = ["aplle", "grape", "Guava"]
vals = [2, 3, 4]
canvas = FigureCanvasTkAgg(fg2, master=tab2)
canvas.draw()
canvas.get_tk_widget().pack(side=BOTTOM, fill=BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, tab2)
toolbar.update()
toolbar.place(x=0, y=543)
canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=True)
plt.title("Bar Chart", fontweight='bold', color='orange', fontsize='17', horizontalalignment='center')
plt.xlabel('Sample', fontweight='bold', color='orange', fontsize='15', horizontalalignment='center')
plt.ylabel('Count', fontweight='bold', color='orange', fontsize='15')
plt.xticks(rotation=45, horizontalalignment='right', fontweight='light', fontsize='small')
plt.yticks(rotation=45, verticalalignment='top', fontweight='light', fontsize='small')

plt.bar(codes_str, vals)
plt.show()

master.mainloop()

I am getting the output as following

enter image description here

When I right click on the table I can see certain options to do in the table, in that list I need to disable edit option. Image reference is shown below.

enter image description here

How could I do that?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Sriram
  • 169
  • 1
  • 9

1 Answers1

1

You can overwrite table.columnactions to remove the Edit menu item:

...
table = TableCanvas(tframe, model=model)
table.columnactions = {}
...

If you want to make all cells not editable, you can override TableCanvas.drawCellEntry():

class MyTableCanvas(TableCanvas):
    def __init__(self, master=None, *args, **kw):
        super().__init__(master, *args, **kw)
        self.columnactions = {}

    def drawCellEntry(self, row, col):
        pass

...

table = MyTableCanvas(tframe, model=model)
...
acw1668
  • 40,144
  • 5
  • 22
  • 34