Try something like this:
import tkinter as tk
class SudokuGUI:
def __init__(self, font_size:int=30):
self.root = tk.Tk()
self.chunks = []
self.frames_list = []
self.font_size = font_size
for i in range(3):
for j in range(3):
self.create_chunk(i, j)
def create_chunk(self, row:int, column:int) -> None:
frame = tk.Frame(self.root, bd=3)
frame.grid(row=row, column=column)
self.frames_list.append(frame)
chunk = []
for row_number in range(3):
for column_number in range(3):
entry = tk.Entry(frame, width=2, justify="center",
font=("", self.font_size),
disabledforeground="black")
entry.grid(row=row_number, column=column_number)
chunk.append(entry)
self.chunks.append(chunk)
def set(self, chunk:int, cell:int, value=None, **kwargs) -> None:
if value is not None:
self.chunks[chunk][cell].delete(0, "end")
self.chunks[chunk][cell].insert("end", value)
self.chunks[chunk][cell].config(**kwargs)
def mainloop(self) -> None:
self.root.mainloop()
app = SudokuGUI()
app.set(chunk=5, cell=5, value=1, state="disabled")
app.mainloop()
I divided the board into chunks of 9 entries. I added the .set
method with sets the state/value of a given cell in a given chunk. You can use it to set the values given. It also disables the user input in those entries.