How do I use tkinter's separator (or another tool) here?

I'm trying to create my own Sudoku, and I managed to write the code providing a perfect random generator of Sudoku grid. enter image description here I get this:

And i want to create separators to canvass the grid (to see clearly 9 cases each grouping 9 number), perhaps using the ttk.Separator function. But I can't manage to "grid" it.. Plus I would need several of them. How should I do ?

If useful, there is the code which implements my Entry cases. I have a big function that assigns each entry a number using the variables v, column and row.

class Input():
    def __init__(self, row, column):
    global v
    v = StringVar()
    self.row = row
    self.column = column
    self.entry = Entry(root, text=v, width=2, justify="center", insertofftime=0, font="Century 20").grid(
        row=row+1, column=column+1, ipadx=13, ipady=13, padx=1, pady=1)

def value_def(self, deflt):

1 answer

  • answered 2021-10-25 03:46 Bryan Oakley

    Instead of a separator, use a frame with a black background, and use padding to leave spaces between the rows and columns.

    Here's an example that illustrates the technique. First I create a class to define one 3x3 grid, and then create a 3x3 grid of class instances. This is by no means the only way to solve this problem, but it shows what it looks like when you add space between items with grid.

    import tkinter as tk
    class SmallGrid(tk.Frame):
        def __init__(self, parent):
            super().__init__(parent, background="black")
            self.entries = {}
            self.grid_rowconfigure((0,1,2), weight=1, uniform="equal")
            self.grid_columnconfigure((0,1,2), weight=1, uniform="equal")
            for row in (0, 1, 2):
                for column in (0, 1, 2):
                    entry = tk.Entry(self, width=2, borderwidth=0)
                    entry.grid(row=row, column=column, padx=2, pady=2, sticky="nsew")
                    self.entries[row,column] = entry
    root = tk.Tk()
    root.grid_rowconfigure((0,1,2), weight=1, uniform="equql")
    root.grid_columnconfigure((0,1,2), weight=1, uniform="equal")
    groups = {}
    for row in (0, 1, 2):
        for column in (0, 1, 2):
            group = SmallGrid(root)
            group.grid(row=row, column=column, padx=2, pady=2)
            groups[row, column] = group


How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum