I'm using pandastable to implement a pandas dataframe into my tkinter window however, an error:
'NoneType' object has no attribute 'bind_all'
Keeps coming up when I use this line:
table = pt = Table(window, dataframe=stats)
full code:
import tkinter as tk
import pandas as pd
from pandastable import Table, TableModel
places = {"Place":['1st'], "Name":['Derik'], "Time":['1.89']}
window = tk.Tk()
stats = pd.DataFrame.from_dict(places)
table = Table(window, dataframe=stats)
CodePudding user response:
The error is because pandastable
wants you to put the widget inside a container and not a window. You can find this out by checking the line 88 and line 264 of the pandastable
source code:
class Table(Canvas):
...
def __init__(self, parent=None, model=None, dataframe=None, ...):
self.parentframe = parent # Line 88
...
def doBindings(self):
...
self.parentframe.master.bind_all("<KP_8>", self.handle_arrow_keys) # Line 264
As you can see, self.parentframe
is the parent you pass in, in your case, window
. And in line 264, they access the master
of the self.parentframe
, which is None
because root windows don't have masters. But other widgets like frames do.
So all you have to do is, put this widget inside a container like Frame
:
frame = tk.Frame(window)
frame.pack()
table = Table(frame, dataframe=stats)
table.show()