I've been playing around with tkinter and loving what I can do. I'm a total noob, however, and wanting to make my own matrix multiplier I've run into numerous problems. My goal is to create two grids of tk entries and be able to call them back later with .get, when I call txt_ent_a.get() I get an error: list has no attribute 'get'.
I found these other questions that have helped me get this far:
List of lists changes reflected across sublists unexpectedly
How can I create a list of entries in tkinter
tkinter: Button instance has no attribute 'get'
And this one that is basically the same as my question, though I didn't really understand how to take the conceptual answer and convert it into code:
Saving variables in 'n' Entry widgets Tkinter interface
I know what I have created as "entry_list" is just an empty list of lists. My real question is: how do I loop through making entry widgets and key or objects (I'm shaky on the lingo) that I can loop through using .get() on later, which I can then make into a list of lists (a matrix) that I can use in a function?
Because I'm so new to Python, I'm not sure if I just need to add a StringVar somehow, or .pack something somehow... I believe .pack is a tkinter thing. I'll try and keep my code cleanish, thank you for any help.
from tkinter import *
import tkinter as tk
window = Tk()
lbl1 = Label(window, text="# of rows: 3").grid(column=0, row=0)
lbl2 = Label(window, text="# of cols: 2").grid(column=0, row=1)
window.geometry('250x250')
def clickedc(): #create matrix click event
row = (3) #In final version these will be the numbers I loop over when
col = (2) #making the entries in question.
lblA = Label(window, text="Input matrix:").grid(column=(int(col/2)), row=3)
entry_list = [] #This is what I want to be a list I can .get() from later
r = 1
for r in range(int(row)):
entry_list.append([])
c = 1
for c in range(int(col)):
entry_list[-1].append(tk.Entry(window, width=10).grid(column=c, row=4 + r))
def clickeds(): #Solving click event
r = 1
matrix_A = [] #The matrix I want to put the values into, for reference
for r in range(int(row)):
c = 1
for c in range(int(col)):
matrix_A[r - 1:c - 1] = entry_list.get("1.0",'end-1c') #Causes Error
#Here I'll: output a new matrix as a grid of labels.ex: #1 1
btn_s = Button(window, text="Solve", command=clickeds) #1 0
btn_s.grid(column=int(col) + 1, row=3) #0 1
btn_c = Button(window, text="Create", command=clickedc)
btn_c.grid(column=3, row=1)
window.mainloop()
I hope this code is clear enough. Any advice is welcome, I assume I code rather poorly.