Ren
Ren

Reputation: 47

Unresolved reference using tkinter in python to build a table

Hello there I am currently trying to build a table using tkinter in python, trying to get json data to be displayed in a table format once the submit button is clicked but I have encountered a issue with the code as a unresolved reference error but the rest of my code seems to be working just fine. Below is a excerpt of my code I seem to get the error with the total_rows loop and I have tried to change the indents of the code which jsut seems to not work so I am not sure how to proceed.

from tkinter import *
class Table:
    def data(self):
        def _init__(self,window):
         for i in range(total_rows):
            for j in range(total_columns):

                self.e(window, width=20, fg="black",
                       font="Arial")

                self.e.grid(rows=i, columns=j)
                self.e.insert(END, file[i][j])

                file = open('dataset.json')  # make sure they r in same location to do this
                data = json.load(file)
                print(data)
                var.set(data)
                window.update_idletasks()
                var = StringVar()
                var.set(" ")

                total_rows = len(file)
                total_columns = len(file[0])
                btn = Button(window, text="Submit", fg='blue', command=data)
                btn.place(x=120, y=120)
                window = Tk()
                t = Table(window)
                window.mainloop()

Upvotes: 1

Views: 135

Answers (1)

Aman Khan
Aman Khan

Reputation: 36

I think you forgot a _ in the constructor:

def data(self):
    def __init__(self,window):
     for i in range(total_rows):
        for j in range(total_columns):
...

Upvotes: 2

Related Questions