How to load a grid into tkinter from file
I am making a program similar to the memory game where i load a file and put it on a grid in tkinter.
I am currently having problems with this part of my code:
with open("Words.txt","r") as tenWordFile: for count in range(10): tenWordLine = tenWordFile.readline() tenWordLine = tenWordLine.strip("\n") Line = tenWordLine.split("\t") Words.append(Line) for r in range (3): for c in range (3): gridLabel = Label(app, text = Words (r,c),borderwidth = 1 ).grid(row=r,column=c) app.mainloop()
When i run my program i get an error:
Exception in Tkinter callback Traceback (most recent call last): File "E:\python\lib\tkinter\__init__.py", line 1487, in __call__ return self.func(*args) File "E:\computer science\Controlled assessment 2\new cs.py", line 33, in tenWordGame gridLabel = Label(app, text = Words (r,c),borderwidth = 1 ).grid(row=r,column=c) TypeError: 'list' object is not callable
I am looking for a solution to print out a 3x3 grid with random words from my words file.
Additionally, i am looking for a more pythonic way to this code aswell.
Lastly, thanks for reading and attempting to help me.
Words is a list. You can't call it like function using (). You have to use  - Words[some_index] or Words[some_index][other_index] if it is two-dimensional list.
BTW: gridLabel = Label(...).grid(...) will assigns None to gridLabel because grid(...) always returns None.
If you don't need gridLabel in other part of code you can skip gridLabel =
If you need gridLabel then do
gridLabel = Label(...) gridLabel.grid(...)