Home > Net >  How do I access specific element of this Entry matrix
How do I access specific element of this Entry matrix

Time:03-13

I am making a Sudoku game, so I want to create matrix of Entry elements which could be given a value of an existing board. I need to access specific element of that matrix and assign a value to it. I also need to know if I can lock Entry so it cannot be edited?

for i in range(9):
    for j in range(9):
        e = tk.Entry(root, bg='white', width=2, font=('calibri', 20), justify='center')
        e.grid(row=i, column=j)

CodePudding user response:

The simplest solution is to save the entries to a list or dictionary.

entries = {}
for i in range(9):
    for j in range(9):
        e = tk.Entry(root, bg='white', width=2, font=('calibri', 20), justify='center')
        e.grid(row=i, column=j)
        entries[i,j] = e
...
foo = entries[2,2].get()
  • Related