Home > Net >  Traceback error in creating columns in tkintertable
Traceback error in creating columns in tkintertable

Time:11-28

My intent is to create a table with columns only, this is my code:

            tframe = Frame(auto_publish_frame)
            tframe.place(x=0, y=285, height=150, width=500)

            model = TableModel()

            table = TableCanvas(tframe, model, read_only=True, cellwidth=116, rowheight=25, rowheaderwidth=30,
                                cellbackgr='#e3f698',
                                thefont=('Arial', 12), rowselectedcolor='#e4f1fe')
            table.createTableFrame()
            table.addColumn(newname='File')

and I get this type of error:

Traceback (most recent call last):
  File "C:\Users\39377\anaconda3\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\39377\anaconda3\lib\site-packages\tkintertable\Tables.py", line 2451, in handle_mouse_move
    if x > self.tablewidth w:
AttributeError: 'ColumnHeader' object has no attribute 'tablewidth'

What's the problem?

CodePudding user response:

You never set this attribute to your table. Maybe you are missing the syntax self. before or you entirly dosent do it or you may set it in a function that isnt called. Without a minimal reproducible example you make me guess.

class ExampelA():
    def __init__(self):
        self.tablewidth = 500
class ExampelB():
    def __init__(self):
        return None
    def set_tablewidth(self):
        self.tablewidth = 500
class ExampelC():
    def __init__(self):
        tablewidth = 500
a = ExampelA()
b = ExampelB()
c = ExampelC()
#print(a.tablewidth)
#print(b.tablewidth)
#print(c.tablewidth)
b.set_tablewidth()
#print(b.tablewidth)

delete a hash symbol and see what happens. ExampleA is the way I tried to tell you in the comments.

CodePudding user response:

Here this is the part that interests you:

class MainPage:

    def __init__(self, root):
        self.root = root
        self.is_login = 0
        self.root.title("Instagram Tool")
        self.root.geometry("1200x600")
        self.root.resizable(False, False)

        # Create main menu frame
        frame_menu = Frame(self.root, bd=0, bg="black")
        frame_menu.place(x=0, y=0, height=600, width=300)
        
        '''other code'''
        # Auto publish button
        auto_publish_button = Button(frame_menu, text="Auto publish", command="set")
        auto_publish_button.place(x=0, y=500, height=100, width=300)

        
        '''other code'''

        def auto_publish(event):
            '''other code'''

            # Set view files selected

            tframe = Frame(auto_publish_frame)
            tframe.place(x=0, y=285, height=150, width=500)

            model = TableModel()

            table = TableCanvas(tframe, model, read_only=True, cellwidth=116, rowheight=25, rowheaderwidth=30,
                                cellbackgr='#e3f698',
                                thefont=('Arial', 12), rowselectedcolor='#e4f1fe')

            table.createTableFrame()

            table.addColumn(newname='File')
        
            '''other code'''


  • Related